Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7552841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:53:16+00:00 2026-05-30T10:53:16+00:00

I have a problem on ICS when I try to use google calendar api.

  • 0

I have a problem on ICS when I try to use google calendar api. To get a list of events, I have a AsyncTask and inside doInBackground() I make the service calls but still I receive the NetworkOnMainThreadException error.

Here is my code:

I call my AsyncTask like this:

new GoogleCalendarEvents().execute(new Object());

And my AsyncTask looks like this:

private class GoogleCalendarEvents extends AsyncTask<Object, Object, Object> {

        @Override
        protected Object doInBackground(Object... objects) {

            OAuthManager manager = OAuthManager.getInstance();
            /* login to google api and get the auth token */
            manager.doLogin("", true, mActivity, new OAuthManager.AuthHandler() {
                @Override
                public void handleAuth(Account account, String authToken) {
                    if (account != null) {
                        /* create a google Calendar service if the returned account is not null */
                        com.google.api.services.calendar.Calendar service = CalendarServiceBuilder.build(OAuthManager.getInstance().getAuthToken());
                        try {

                            /* get the list of events for the primary calendar */
                            /* ---------HERE THE APP IS CRUSHING  --------- */
                            mEvents = service.events().list(mCalendarId).execute();

                            while (true) {
                                /* get the next page token if any */
                                String pageToken = mEvents.getNextPageToken();

                                if (pageToken != null && !pageToken.equals("")) {
                                    /* if there are other pages, get the next page */
                                    Events newPageEvents = service.events().list(mCalendarId)
                                            .setPageToken(pageToken).execute();

                                    for (Event event : newPageEvents.getItems()) {
                                        /* loop through all the events and add them into the mEvents  */
                                        mEvents.put(event.getId(), event);
                                    }

                                } else {
                                    break;
                                }
                            }
                            /* make sure we wont have memory leaks */
                            mActivity = null;
                            /* notify the caller that the calendar events are ready */
                            mEventsReceiverCallback.calendarEventsReceived(true);
                            mEventsReceiverCallback = null;

                        } catch (IOException e) {
                            /* let the user know that the event could not be created */
                            Utility.showInformationDialog(mActivity, mActivity.getString(R.string.error),
                                    mActivity.getString(R.string.error_message_bad_request_get_events));
                            /* make sure we wont have memory leaks */
                            mActivity = null;
                            /* print the error into the log */
                            e.printStackTrace();
                            /* notify the caller that the manager could not get the calendar events */
                            mEventsReceiverCallback.calendarEventsReceived(false);
                            mEventsReceiverCallback = null;

                        }

                    } else {

                        /* le the user know that the event could not be created */
                        Utility.showInformationDialog(mActivity, mActivity.getString(R.string.error),
                                mActivity.getString(R.string.error_message_connection));
                        /* make sure we wont have memory leaks */
                        mActivity = null;
                        /* notify the caller that the manager could not get the calendar events */
                        mEventsReceiverCallback.calendarEventsReceived(false);
                        mEventsReceiverCallback = null;

                    }
                }
            });

            return null;
        }

    }

And the log:

02-22 10:32:08.597: ERROR/AndroidRuntime(13924): FATAL EXCEPTION: main
        android.os.NetworkOnMainThreadException
        at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
        at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
        at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
        at java.net.InetAddress.getAllByName(InetAddress.java:220)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
        at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
        at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
        at com.google.api.client.http.apache.ApacheHttpRequest.execute(ApacheHttpRequest.java:58)
        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:639)
        at com.google.api.client.http.json.JsonHttpClient.execute(JsonHttpClient.java:257)
        at com.google.api.client.googleapis.services.GoogleClient.execute(GoogleClient.java:121)
        at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:67)
        at com.google.api.services.calendar.Calendar$Events$List.execute(Calendar.java:2643)
        at /* here is the error, I think */com.google.calendar.manager.business.CalendarEventProvider$GoogleCalendarEvents$1.handleAuth(CalendarEventProvider.java:118)
        at com.google.calendar.manager.utils.OAuthManager$1.run(OAuthManager.java:194)
        at android.accounts.AccountManager$10.run(AccountManager.java:1264)
        at android.os.Handler.handleCallback(Handler.java:605)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4424)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        at dalvik.system.NativeStart.main(Native Method)

Here says that I have to use AndroidHttp.newCompatibleTransport() as the transport class, and I do use it in my CalendarServiceBuilder.

What could cause this error and how I can solve the problem?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:53:17+00:00Added an answer on May 30, 2026 at 10:53 am

    It seems the problem was in the manifest.. I had this attribute in the uses-sdk tag:

    android:targetSdkVersion="10"
    

    After I removed this attribute, the app worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem when I try insert some data to Informix TEXT column via
I have problem when I try to set a background to .header - nothing
I have problem with jCaret plugin in IE. jCaret downloads I want to get
i have problem passing data from one page to another using GET, for example
I have problem in C#. I have a list box and a class called
I have problem with richfaces calendar. I want to see only year and month
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.