我正在谷歌驱动器上开发应用程序,我想在谷歌网页上尝试android-quickstart,我已经按照示例代码,当我尝试从它获取令牌时,它有错误,这里是我的代码
protected void onActivityResult (final int requestCode, final int resultCode, final Intent data) { switch (requestCode) {
case REQUEST_ACCOUNT_PICKER:
if (resultCode == RESULT_OK && data != null && data.getExtras() != null) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
Toast.makeText(this," Account Name = "+accountName,3000).show(); //show my account name
if (accountName != null) {
credential.setSelectedAccountName(accountName);
service = getDriveService(credential);
String token = data.getStringExtra("token");
System.out.println(token);
}
}
break;
case REQUEST_AUTHORIZATION:
if (resultCode == Activity.RESULT_OK) {
getDriveContents();
} else {
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
}
break;
}
}
并且logcat显示
02-07 13:04:24.830:E / AndroidRuntime(13906):致命异常:主要 02-07 13:04:24.830:E / AndroidRuntime(13906):java.lang.RuntimeException:传递结果失败ResultInfo {who = null,request = 1,result = -1,data = Intent {(has extras)}} to activity {com.example.testfyp / com.example.testfyp.MainActivity}:java.lang.NullPointerException 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.ActivityThread.deliverResults(ActivityThread.java:3162) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.ActivityThread.handleSendResult(ActivityThread.java:3205) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.ActivityThread.access $ 1100(ActivityThread.java:138) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1255) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.os.Handler.dispatchMessage(Handler.java:99) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.os.Looper.loop(Looper.java:213) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.ActivityThread.main(ActivityThread.java:4787) 02-07 13:04:24.830:E / AndroidRuntime(13906):at java.lang.reflect.Method.invokeNative(Native Method) 02-07 13:04:24.830:E / AndroidRuntime(13906):at java.lang.reflect.Method.invoke(Method.java:511) 02-07 13:04:24.830:E / AndroidRuntime(13906):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:809) 02-07 13:04:24.830:E / AndroidRuntime(13906):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 02-07 13:04:24.830:E / AndroidRuntime(13906):at dalvik.system.NativeStart.main(Native Method) 02-07 13:04:24.830:E / AndroidRuntime(13906):引起:java.lang.NullPointerException 02-07 13:04:24.830:E / AndroidRuntime(13906):at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298) 02-07 13:04:24.830:E / AndroidRuntime(13906):at com.example.testfyp.MainActivity.onActivityResult(MainActivity.java:88) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.Activity.dispatchActivityResult(Activity.java:5192) 02-07 13:04:24.830:E / AndroidRuntime(13906):在android.app.ActivityThread.deliverResults(ActivityThread.java:3158) 02-07 13:04:24.830:E / AndroidRuntime(13906):... 11更多
我不知道如何解决它