相关疑难解决方法(0)

Cast应用程序中的"GoogleApiClient尚未连接"异常

我正在开发一个将内容投射到Chromecast的Android应用程序.有时在我com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacksonConnected方法实现中,我得到了一个

java.lang.IllegalStateException: GoogleApiClient is not connected yet.
Run Code Online (Sandbox Code Playgroud)

例外.

这是堆栈跟踪:

    FATAL EXCEPTION: main
 Process: com.joaomgcd.autocast, PID: 13771
 java.lang.IllegalStateException: GoogleApiClient is not connected yet.
    at com.google.android.gms.internal.eg.a(Unknown Source)
    at com.google.android.gms.common.api.GoogleApiClient.b(Unknown Source)
    at com.google.android.gms.cast.Cast$CastApi$a.launchApplication(Unknown Source)
    at com.joaomgcd.autocast.media.MediaConnectionCallbacks.onConnected(MediaConnectionCallbacks.java:37)
    at com.google.android.gms.internal.dx.b(Unknown Source)
    at com.google.android.gms.common.api.GoogleApiClient.bn(Unknown Source)
    at com.google.android.gms.common.api.GoogleApiClient.f(Unknown Source)
    at com.google.android.gms.common.api.GoogleApiClient$2.onConnected(Unknown Source)
    at com.google.android.gms.internal.dx.b(Unknown Source)
    at com.google.android.gms.internal.dx.bT(Unknown Source)
    at com.google.android.gms.internal.dw$h.b(Unknown Source)
    at com.google.android.gms.internal.dw$h.b(Unknown Source)
    at com.google.android.gms.internal.dw$b.bR(Unknown Source)
    at com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) …
Run Code Online (Sandbox Code Playgroud)

android google-cast chromecast

12
推荐指数
3
解决办法
3万
查看次数

GoogleApiClient尚未连接,即使已调用onConnected并且我正在onCreate中创建我的GoogleApiClient

我在这里查看了这个问答:GoogleApiClient正在抛出"GoogleApiClient尚未连接"之后onConnected函数被调用

因为它似乎与我所经历的相似,但事实并非如此.该用户的问题是他们在onStart()方法中声明了他们的api客户端,我在onCreate()方法中创建了我的答案.然而,我仍然得到同样的错误.

以下是我对这三种方法的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /* Butter knife creates the variables */
    ButterKnife.bind(this);

    /* Startup location services */
    locationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000)        // 10 seconds, in milliseconds
            .setFastestInterval(1 * 1000); // 1 second, in milliseconds

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    progressBar.setVisibility(View.INVISIBLE);

    refreshImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getForecast();
        }
    });
}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
    Log.i("Connected!!!", "WERE CONNECTED");
}

@Override
protected void …
Run Code Online (Sandbox Code Playgroud)

java android location google-api-client

3
推荐指数
1
解决办法
3136
查看次数