谷歌+ for android(获取空指针)

Saa*_*mud 31 android google-plus

我正试图通过浏览此官方谷歌文档来整合Google+ for Android .按照给出的步骤后:

  1. Dwnload最新的SDK
  2. 使用Android 4.4.2,
  3. 配置Eclipse使用Java 1.7(虽然它说使用1.6,我猜它不是我的问题)
  4. 然后通过提供Package.Name和启用Google+ API Sha1.然后我配置示例应用程序 并附加google-play-services_lib(导入)到它.

现在,当我运行应用程序时,它在MainActivity中提供了Exception

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Plus.API, null) // here the exception (nullPointerException) 
    .addScope(Plus.SCOPE_PLUS_LOGIN).build();
Run Code Online (Sandbox Code Playgroud)

我在物理设备Android 4.1.2上运行它.

通过谷歌,但没有运气.

logcat的:

05-27 10:23:46.808: D/ActivityThread(11136): setTargetHeapUtilization:0.25 05-27 10:23:46.808: D/ActivityThread(11136): setTargetHeapIdealFree:8388608 05-27 10:23:46.808: D/ActivityThread(11136): setTargetHeapConcurrentStart:2097152 05-27 10:23:47.228: D/AndroidRuntime(11136): Shutting down VM 05-27 10:23:47.228: W/dalvikvm(11136): threadid=1: thread exiting with uncaught exception (group=0x411eb438) 05-27 10:23:47.228: E/AndroidRuntime(11136): FATAL EXCEPTION: main 05-27 10:23:47.228: E/AndroidRuntime(11136): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mygoogleplus/com.example.mygoogleplus.GooglePlusMainActivity}: java.lang.NullPointerException: Null options are not permitted for this Api 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.access$700(ActivityThread.java:143) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.os.Handler.dispatchMessage(Handler.java:99) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.os.Looper.loop(Looper.java:137) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.main(ActivityThread.java:4960) 05-27 10:23:47.228: E/AndroidRuntime(11136): at java.lang.reflect.Method.invokeNative(Native Method) 05-27 10:23:47.228: E/AndroidRuntime(11136): at java.lang.reflect.Method.invoke(Method.java:511) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 05-27 10:23:47.228: E/AndroidRuntime(11136): at dalvik.system.NativeStart.main(Native Method) 05-27 10:23:47.228: E/AndroidRuntime(11136): Caused by: java.lang.NullPointerException: Null options are not permitted for this Api 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.google.android.gms.internal.fq.b(Unknown Source) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.google.android.gms.common.api.GoogleApiClient$Builder.addApi(Unknown Source) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.example.mygoogleplus.GooglePlusMainActivity.onCreate(GooglePlusMainActivity.java:89) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.Activity.performCreate(Activity.java:5203) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)

Nin*_*der 119

以下对我有用.

只需以这种方式传递一个参数即可.

.addApi(Plus.API) 
Run Code Online (Sandbox Code Playgroud)

代替

.addApi(Plus.API, null)
Run Code Online (Sandbox Code Playgroud)

要么

你也可以传递一个PlusOptions对象

.addApi(Plus.API, Plus.PlusOptions.builder().build())
Run Code Online (Sandbox Code Playgroud)

这些解决方案都可以使用.

  • 这个G +的东西充满了像这样的愚蠢问题.谢谢你为他们报道! (6认同)