2017-09-14 72 views
0

因此,我昨天一直在試圖解決這個問題。 我的應用應該連接到GooglePlay(爲了訪問排行榜),但只要我運行GoogleApiClient.connect()方法,應用崩潰(與.enableAutoManage相同的問題)。我什至不能捕捉到一個錯誤,因爲客戶似乎運行一個新的線程。當試圖連接到谷歌播放時,應用程序崩潰

我初始化GoogleApiClient如下:當我運行gaClient.connect()的應用程序崩潰,即使我把try-catch聲明周圍

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

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' } 

我也試過版本: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

感謝但這並不能工作,沒有一個方法被調用(我想我已經實現這一次,fo​​rgott一提的是) – Regedit

+0

我看到堆棧跟蹤和觀察到的錯誤是在線'LogCollectManager.getUserType ()'請發佈與此相關的代碼.. –

+0

問題是,我從來沒有調用該方法,甚至不使用LogCollectManager,在運行'connect()'方法後,該行由GoogleApiClient調用 – Regedit

相關問題