我的應用程序是以地圖爲中心的。我經常撥打requestLocationUpdates()
。有一段時間,當它被調用時,我得到這個exception
。或者在任何其他調用這種方法的地方。我看到了特種部隊提出的解決方案,遺憾的是似乎沒有任何東西可以用於我。即使我打電話給mLocationClient.connect()
,也不能保證它立即連接,糾正我,如果我錯了。我如何解決這個問題?未連接。調用Connect或等待onConnected()被調用
情況下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;
,這是引發的異常:
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$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
很好的解釋,謝謝!! – Abby
這些種類的解釋總是值得讚賞的。謝謝! – 0x5f3759df
即使它在onConnected()方法中,我也在同一行代碼中得到了此錯誤。你怎麼做的? – Price