JavaGmailapi在Android上获取消息
我正在尝试使用GmailApi从gmail获取所有消息,但是当我运行代码时,这个错误出现了
“java.lang.RuntimeException:无法启动活动组件信息{com.yousefelsayed.myemail/com.yousefelsayed.myemail.MainActivity}:java.lang.IllegalArgumentException:名称不能为空:null”
它告诉我错误来自这条线
ListThreadsResponse listResponse = mService.users().threads().list("me").execute();
有什么问题
霉菌代码:
mCredential = GoogleAccountCredential.usingOAuth2(
getApplicationContext(), SCOPES)
.setBackOff(new ExponentialBackOff());
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
mService = new com.google.api.services.gmail.Gmail.Builder(
transport, jsonFactory, mCredential)
.setApplicationName(getResources().getString(R.string.app_name))
.build();
try {
ListThreadsResponse listResponse = mService.users().threads().list("me").execute();
} catch (IOException e) {
e.printStackTrace();
}
编辑:
完全错误:
05-28 09:15:39.836 22385-22385/com.yousefelsayed.myemail E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yousefelsayed.myemail, PID: 22385
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yousefelsayed.myemail/com.yousefelsayed.myemail.MainActivity}: java.lang.IllegalArgumentException: the name must not be empty: null
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2583)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
at 安卓.app.ActivityThread.-wrap11(ActivityThread.java)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
at 安卓.os.Handler.dispatchMessage(Handler.java:111)
at 安卓.os.Looper.loop(Looper.java:207)
at 安卓.app.ActivityThread.main(ActivityThread.java:5765)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:684)
Caused by: java.lang.IllegalArgumentException: the name must not be empty: null
at 安卓.accounts.Account.<init>(Account.java:48)
at com.google.安卓.gms.auth.zzg.getToken(Unknown Source)
at com.google.安卓.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
at com.google.api.client.googleapis.extensions.安卓.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:267)
at com.google.api.client.googleapis.extensions.安卓.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:292)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:880)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:542)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:475)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:592)
at com.yousefelsayed.myemail.MainActivity.onCreate(MainActivity.java:136)
at 安卓.app.Activity.performCreate(Activity.java:6301)
at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
at 安卓.app.ActivityThread.-wrap11(ActivityThread.java)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
at 安卓.os.Handler.dispatchMessage(Handler.java:111)
at 安卓.os.Looper.loop(Looper.java:207)
at 安卓.app.ActivityThread.main(ActivityThread.java:5765)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:684)
05-2809:15:39.983805-1769/?E/传感器:手柄河流手柄(0)
共 (0) 个答案