Not connected. Call Connect or wait for onConnected() to be called

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

My app is map-centric. I call requestLocationUpdates() often. Once in a while, I get this exception when its called. Or in any other place which calls such method. I saw the solutions suggested on SOF, sadly nothing seems to work for me. Even if i call mLocationClient.connect(), there is no guarantee that it connects immediately, correct me if i'm wrong. How do i solve this problem?

case R.id.btnContinue:

gpsLocationDailog.cancel();          int isGooglePlayServiceAvilable = GooglePlayServicesUtil                 .isGooglePlayServicesAvailable(getApplicationContext());         if (isGooglePlayServiceAvilable == ConnectionResult.SUCCESS) {             /** thorws shitty expectiosn **/             mLocationClient.connect();             try {                 mLocationClient.requestLocationUpdates(REQUEST, this);                 mCurrentLocation = mLocationClient.getLastLocation();                 fireQueryToGetTheResponse(latitude, longitude);                 rl.setVisibility(View.VISIBLE);                 mDrawerLayout.setVisibility(View.GONE);                 mSlidingUpPanelLayout.setVisibility(View.GONE);             } catch (IllegalStateException e) {                 mLocationClient.connect();                 Log.e(TAG, " Waiting for onConnect to be called");             }         } else {             GooglePlayServicesUtil.getErrorDialog(                     isGooglePlayServiceAvilable,                     SqueakeeMapListViewPager.this, 0).show();         }          break;

and this is the exception that is raised:

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called. at com.google.android.gms.internal.de.bc(Unknown Source) at com.google.android.gms.internal.ez.a(Unknown Source) at com.google.android.gms.internal.ez$c.bc(Unknown Source) at com.google.android.gms.internal.ey.requestLocationUpdates(Unknown Source) at com.google.android.gms.internal.ez.requestLocationUpdates(Unknown Source) at com.google.android.gms.internal.ez.requestLocationUpdates(Unknown Source) at com.google.android.gms.location.LocationClient.requestLocationUpdates(Unknown Source) at org.application.app.squeakee.SqueakeeMapListViewPager.onClick(SqueakeeMapListViewPager.java:1936) at android.view.View.performClick(View.java:4475) at android.view.View$PerformClick.run(View.java:18786) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5493) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndAr  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!