isGooglePlayServicesAvailable nullPointerException

时间:2014-08-25 06:59:13

标签: java android google-play-services

我使用此方法检查Google Play是否可用:

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(status == ConnectionResult.SUCCESS) {
  do something
}

除少数设备外,一切都很好。现在,我注意到阿尔卡特ONE TOUCH 4033X和索尼C2105发生了故障。我经常在这些设备上发布崩溃报告,我不知道为什么会发生这种情况。

BRAND=TCT, PRODUCT=Yaris_M, TOTAL_MEM_SIZE=2246361088, AVAILABLE_MEM_SIZE=1537773568, CUSTOM_DATA=, STACK_TRACE=java.lang.NullPointerException
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)

at package.ShopsFragment.servicesConnected(ShopsFragment.java:685)
at package.ShopsFragment.getLatAndLng(ShopsFragment.java:338)
at package.ShopsFragment.onConnected(ShopsFragment.java:673)
at com.google.android.gms.internal.hb$c.onConnected(Unknown Source)
at com.google.android.gms.internal.hc.c(Unknown Source)
at com.google.android.gms.internal.hc.cp(Unknown Source)
at com.google.android.gms.internal.hb$h.b(Unknown Source)
at com.google.android.gms.internal.hb$h.d(Unknown Source)
at com.google.android.gms.internal.hb$b.fv(Unknown Source)
at com.google.android.gms.internal.hb$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5400)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
at dalvik.system.NativeStart.main(Native Method)

编辑: 在onCreated我有:

if (status == ConnectionResult.SUCCESS) 
{
    if(network_enabled) 
    {
    getLocation();
    } 
}

public void getLocation() 
    {
        clearTextFromSearch = true;
        searchEditText.setText("");

        locationClient.connect();
    }

然后在onConnected上我调用getLatAndLng()

private void getLatAndLng() 
    {
        clearList = true;
        nPages = 0;

        clearTextFromSearch = true;
        searchEditText.setText("");

        currentLocation = locationClient.getLastLocation();

        locationClient.disconnect();

        if(currentLocation != null)
        {
            lat = currentLocation.getLatitude();
            lng = currentLocation.getLongitude();

            getShops(lat, lng, nPages);
        }
}

0 个答案:

没有答案