2017-08-30 92 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