0

Google Play LocationClient を使用しています。ドキュメントに記載されているように、 onCreate() で初期化しました。

mLocationClient = new LocationClient(this, this, this);

onStart() で接続を行っています

mLocationClient.connect();

私の Android フォンでは正常に動作しますが、開発者コンソールでは、NullPointerException がconnect()行で発生していることがわかります。これはどのように起こりますか?

4

1 に答える 1

0

これはおそらく、NPE の原因となっているデバイスに Google Play サービスがないか、最新ではないことが原因です。onCreateで確認できます

int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (errorCode != ConnectionResult.SUCCESS)
{
        if (DEBUG) {Log.d(TAG, "errorCode = " + errorCode);}
        Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, this, 
                                1, new DialogCancelListener());
        errorDialog.show();
}

Google ストアにアクセスして更新またはインストールするようユーザーに求めるダイアログが表示されます。
onStart では、null をチェックする必要があります

if (mLocationClient != null)
{
    mLocationClient.connect();
}
于 2013-08-16T18:51:56.003 に答える