Skip to content Skip to sidebar Skip to footer

Android Googleplay Locationclient Is Null, Although Initialized In Oncreate()

I am working with the Google Play LocationClient. I have initialized it in onCreate() as stated in the docs: mLocationClient = new LocationClient(this, this, this); and I am doing

Solution 1:

That is probably because the device that cause the NPE does not have Google Play Service or is not up to dated. In onCreate you can check

interrorCode= GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (errorCode != ConnectionResult.SUCCESS)
{
        if (DEBUG) {Log.d(TAG, "errorCode = " + errorCode);}
        DialogerrorDialog= GooglePlayServicesUtil.getErrorDialog(errorCode, this, 
                                1, newDialogCancelListener());
        errorDialog.show();
}

Which will show a dialog to ask the user to go to Google Store to update or install. In onStart you need to check for null

if (mLocationClient != null)
{
    mLocationClient.connect();
}

Post a Comment for "Android Googleplay Locationclient Is Null, Although Initialized In Oncreate()"