2017-08-30 114 views
0

我有一個應用程序,我想添加Google Play成就。我也跟着這樣的:應用程序在googleApiClient.connect()上崩潰;

https://developers.google.com/games/services/android/init

我有這個在我的清單(用正確的ID):

<meta-data android:name="com.google.android.gms.appstate.APP_ID" 
    android:value="000000000000" /> 
<meta-data android:name="com.google.android.gms.games.APP_ID" 
    android:value="000000000000" /> 

我有這樣的OnStart:

@Override 
protected void onStart() { 
    try 
    { 
     super.onStart(); 
     googleApiClient.connect(); 
    }catch (Exception e) 
    { 
     Exception error; 
     error = e; 
    } 
} 

隨着調試運行,當「.connect()」被執行,它崩潰,並且「TRY CATCH」沒有檢測到它。 這是我的「OnCreate()」。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    googleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
      // add other APIs and scopes here as needed 
      .build(); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_main); 

    lanzarFragments(); 
} 

這是怎麼了我的 「MainActivity」 聲明:

public class MainActivity extends AppCompatActivity implements 
    GoogleApiClient.ConnectionCallbacks, 
    GoogleApiClient.OnConnectionFailedListener 

我GoogleApiClient,被宣告就像我在這裏展示:

public static GoogleApiClient googleApiClient; 

我想補充一點的方法「 lanzarFragments()「,啓動一個片段。我的所有應用程序都帶有碎片,互相更換。但我只有一個Activity,Main,它有我寫的「OnCreate()」。

有關它崩潰的一些想法以及如何解決它?謝謝。

+1

嘗試在'catch'塊中添加'e.printStackTrace();'。然後將日誌添加到您的問題。 – ZeekHuge

+0

我之前做過的嘗試是放置一個斷點。出於這個原因,我知道這個過程不會進入catch塊。我做了你所說的,但我不知道在日誌上找到執行。我必須寫很多文字。我正在看「Android監視器」,「詳細」模式,「僅顯示選定的應用程序」。 –

回答

1

在調用onStart試試這個():

@Override 
protected void onStart() { 
    super.onStart(); 
    mGoogleApiClient.connect(); 
} 
中的onStop

();

@Override 
protected void onStop() { 
    super.onStop(); 
    mGoogleApiClient.disconnect(); 
} 

這是從Official Docs。你不需要try/catch這個方法,因此爲什麼異常沒有被調用。

你能不能發佈你的logcat更詳細的信息,因爲沒有它,別人就無法找到確切的問題。

+0

我試過了,它沒有工作。它來自我粘貼在這個問題上的鏈接;) –

+0

Logcat有超過6000行。 –

+0

確保爲logcat輸出啓用了「僅顯示選擇的應用程序」,並查找任何紅色的行,並在包名後面加上字母「E」。 – pnewby060