安卓:java.lang.IllegalStateException:GoogleApiClient必须连接
问题描述:
我在我的Android应用程序整合谷歌加当我试图登录到谷歌加我的应用程序只是坠毁。它说 -
I am integrating Google Plus in my android app when I was trying to sign in to Google Plus my app just crashed. It says -
java.lang.IllegalStateException: GoogleApiClient must be connected
下面是行号这对堆栈跟踪点,
Below is the line number which stacktrace points towards,
if (Plus.AccountApi.getAccountName(mGoogleApiClient) != null)
@Override
public void onConnected(Bundle connectionHint) {
String personName = "Unknown";
if (Plus.AccountApi.getAccountName(mGoogleApiClient) != null) {
personName = Plus.AccountApi.getAccountName(mGoogleApiClient);
}
}
我已经做了集成的所有步骤,谷歌加入到我的项目发挥服务和注册我的谷歌API的网站应用程序。
I have done all steps for integration, added Google play services to my project and registered my app on Google API's site.
答
的复制:Android:谷歌玩游戏服务连接错误(java.lang.IllegalStateException:GoogleApiClient必须连接)
不管怎么说,修改code为:
Anyways, modify your code to:
@Override
public void onConnected(Bundle connectionHint) {
String personName = "Unknown";
if (isSignedIn()) {
if (Plus.AccountApi.getAccountName(mGoogleApiClient) != null) {
personName = Plus.AccountApi.getAccountName(mGoogleApiClient);
}
}
}