Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google+ for android ( getting null pointer)

I am trying to incorporate Google+ for Android by going through this official google documentation . After following the steps given:

  1. Dwnload latest SDK
  2. Using Android 4.4.2,
  3. Configured Eclipse to use Java 1.7( though it's saying to use 1.6, I am guessing it's not my issue)
  4. Then Enabled the Google+ API by providing Package.Name and Sha1. Then I configure the sample app and attached google-play-services_lib(imported) to it.

Now when Im running the app it is giving Exception in MainActivity's

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

I m running it on physical Device Android 4.1.2.

Going through Google but didn't get any luck.

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)

like image 569
Saad Mahmud Avatar asked May 27 '14 10:05

Saad Mahmud


3 Answers

The following have worked for me.

Just pass on a single parameter in this manner.

.addApi(Plus.API) 

instead of

.addApi(Plus.API, null)

OR

you could also pass it a PlusOptions object

.addApi(Plus.API, Plus.PlusOptions.builder().build())

Either of these solutions will work.

like image 53
Ninja_Coder Avatar answered Oct 24 '22 18:10

Ninja_Coder


You should build Options for that API

.addApi(Plus.API, PlusOptions.builder().build())

If you use GameHelper - you should call setPlusApiOptions before setup.

// Google Play Services
m_GameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_PLUS);
m_GameHelper.setPlusApiOptions( PlusOptions.builder().build() );
m_GameHelper.setup(this);
like image 3
Peter Sokolov Avatar answered Oct 24 '22 18:10

Peter Sokolov


mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN) 
                .build();

Its worked for me. mGoogleApiClient is a object of GoogleApiClient. Pass Only one parameter into addApi(). Like

.addApi(Plus.API)
like image 3
Soumen Das Avatar answered Oct 24 '22 17:10

Soumen Das