1

RunTimeException执行AsyncTask'sexecute() 方法时,我得到了关注。我AsyncTask通过单击其侦听器显示在此错误日志下方的按钮来执行。

05-15 12:56:50.045: W/dalvikvm(25830): threadid=12: thread exiting with uncaught exception (group=0x415052a0)
05-15 12:56:50.070: E/AndroidRuntime(25830): FATAL EXCEPTION: AsyncTask #1
05-15 12:56:50.070: E/AndroidRuntime(25830): java.lang.RuntimeException: An error occured while executing doInBackground()
05-15 12:56:50.070: E/AndroidRuntime(25830):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.lang.Thread.run(Thread.java:856)
05-15 12:56:50.070: E/AndroidRuntime(25830): Caused by: java.lang.IllegalArgumentException: the name must not be empty: null
05-15 12:56:50.070: E/AndroidRuntime(25830):    at android.os.Parcel.readException(Parcel.java:1429)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at android.os.Parcel.readException(Parcel.java:1379)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.android.gms.internal.x$a$a.a(Unknown Source)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:217)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.fooworks.foomanager.EventsActivity$1$1.doInBackground(EventsActivity.java:94)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at com.fooworks.foomanager.EventsActivity$1$1.doInBackground(EventsActivity.java:1)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-15 12:56:50.070: E/AndroidRuntime(25830):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-15 12:56:50.070: E/AndroidRuntime(25830):    ... 5 more
05-15 12:56:50.100: D/dalvikvm(25830): GC_CONCURRENT freed 331K, 7% free 12486K/13319K, paused 13ms+13ms, total 47ms

这是代码:

package com.fooworks.foomanager;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.GooglePlayServicesAvailabilityException;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.googleapis.extensions.android.gms.auth.GooglePlayServicesAvailabilityIOException;
import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.calendar.CalendarScopes;
import com.google.api.services.calendar.model.CalendarList;

public class EventsActivity extends EntriesActivity {

  public static final String CLIENT_ID = "850381918262.apps.googleusercontent.com";

  public static final String API_KEY = "AIzaSyC7t5n2akn2HmDrcbbnkiMPGBhG9Hhuyqc";

  public static final String PREF_GOOGLEACCOUNT_NAME = "googleAccountName";

  public static final int REQUEST_ACCOUNT_PICKER = 8; // take care not to
  // overlap with requests
  // in superclass

  final HttpTransport transport = AndroidHttp.newCompatibleTransport();

  final JsonFactory jsonFactory = new GsonFactory();

  GoogleAccountCredential credential;

  com.google.api.services.calendar.Calendar calendarClient;

  void chooseGoogleAccount() {

    GoogleAccountManager googleAccountManager = new GoogleAccountManager(this);

    Account[] accounts = googleAccountManager.getAccounts();

  }

  private static final String SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";
  //private static final String SCOPE = "oauth2:https://www.googleapis.com/auth/calendar";

  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    System.out.println("HERE!!!");
    System.out.println(CalendarScopes.CALENDAR);

    credential = GoogleAccountCredential.usingOAuth2(this, CalendarScopes.CALENDAR);

    calendarClient = new com.google.api.services.calendar.Calendar.Builder(
      transport, jsonFactory, credential).setApplicationName("Client Event Manager/1.0")
      .build();

    Button testButton = (Button) findViewById(R.id.test);

    testButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        new AsyncTask<Void, Void, Void>() {

          @Override
          protected Void doInBackground(Void... params) {

            try {
               //THIS IS THE LINE CAUSING THE ERROR:
              CalendarList calendarList = calendarClient.calendarList().list().execute();
              System.out.println(calendarList.getItems());

            } catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
              System.out.println("Hello Exception 0!");
              System.out.println(availabilityException.getConnectionStatusCode());
            } catch (UserRecoverableAuthIOException userRecoverableException) {
              System.out.println("Hello Exception !");
              EventsActivity.this.startActivityForResult(userRecoverableException.getIntent(), 99);
            } catch (IOException e) {
              System.out.println("Hello Exception 2!");
              e.printStackTrace();
            }

            return null;

          }

        }.execute();

      }

    });

  }

有人可以阐明导致此错误的原因以及如何解决吗?

4

1 回答 1

0

试试这个方法

    new AsyncTask<String, Void, String>() {
     @Override
              protected String doInBackground(Void... params) {
return null;

            }
 @Override
protected void onPostExecute(String result) {

    super.onPostExecute(result);
             }
}
于 2013-05-15T11:23:20.897 回答