2017-09-14 13 views
0

私は昨日この問題を解決しようとしてきました。 私のアプリはGooglePlayに接続して(リーダーボードにアクセスするために)、GoogleApiClient.connect()メソッドを実行するとアプリがクラッシュします(.enableAutoManageと同じ問題)。私はクライアントが新しいスレッドを実行するように見えるので、エラーをキャッチすることさえできません。Googleの再生に接続しようとするとアプリケーションがクラッシュする

次のように私はGoogleApiClientを初期化します。

GoogleApiClient gaClient; 
gaClient = new GoogleApiClient.Builder(this) 
     .addOnConnectionFailedListener(this) 
     .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
     .build(); 

をできるだけ早く私はgaClient.connect()アプリのクラッシュを実行すると、私はそれを回避try-catch文を入れていても。 onConnectionFailedリスナーはアクティブ化されません。 私はまた、バージョン試みた

dependencies { 
compile fileTree(include: ['*.jar'], dir: 'libs') 
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
    exclude group: 'com.android.support', module: 'support-annotations' 
}) 
compile 'com.android.support:appcompat-v7:26.+' 
compile 'com.android.support:design:26.+' 
compile 'com.google.android.gms:play-services-games:11.0.2' 
compile 'com.google.android.gms:play-services-auth:11.0.2' 
compile 'com.google.android.gms:play-services-ads:11.0.2' 
compile 'com.android.support.constraint:constraint-layout:1.0.2' 
testCompile 'junit:junit:4.12' } 

プロジェクトで、次の依存関係をHAVA:11.0.4

スタックトレースは次のようになりますが:

java.lang.NullPointerException: Attempt to invoke virtual method 'int com.huawei.lcagent.client.LogCollectManager.getUserType()' on a null object reference 
at com.android.server.util.ReportTools.getUserType(ReportTools.java:86) 
at com.android.server.util.ReportTools.isBetaUser(ReportTools.java:73) 
at com.android.server.util.ReportTools.report(ReportTools.java:58) 
at com.android.server.util.HwUserBehaviourRecord.appExitRecord(HwUserBehaviourRecord.java:65) 
at com.android.server.am.ActivityManagerService$UiHandler.handleMessage(ActivityManagerService.java:1523) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:150) 
at android.os.HandlerThread.run(HandlerThread.java:61) 
at com.android.server.ServiceThread.run(ServiceThread.java:46) 

スタックトレースを私はそれを持っていると信じているので私の電話機に関係するものですが、残念ながら私は別のものやエミュレータへのアクセス権を持っていません。これを修正できない場合の回避策はありますか?

私はまた、ユーザーが選択したいアカウントを選択させる機能が欠けていますが、これは既にconnect()メソッドに統合されていますか?

私は既に非常によく似た質問があることを知っていますが、答えはどれも私のために働いていません。

ありがとうございます!

答えて

0

GoogleApiClientをビルドするときには、ConnectionCallbackも追加する必要があります。

これを初期化に追加します。

GoogleApiClient gaClient; 
gaClient = new GoogleApiClient.Builder(this) 
    .addOnConnectionFailedListener(this) 
    .addConnectionCallbacks(this) // with this you will have to implement another method onConnected and then .connect method will work fine. 
    .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
    .build(); 
+0

おかげが、これは方法のいずれもが(それを言及するために、私はこれらの一回実施していたと思いますが、forgott)と呼ばれていない、どちらか動作しません – Regedit

+0

私は、スタックトレースを見て、そのエラーを観察ライン 'LogCollectManager.getUserTypeであります() 'これに関連するコードを投稿してください。 –

+0

問題は、私が決してそのメソッドを呼び出すことはなく、' LogCollectManager'を使用することです。この行は 'connect()'メソッドを実行した後にGoogleApiClientによって呼び出されます – Regedit

関連する問題