问题描述
我的应用程序是地图为中心。我称之为 requestLocationUpdates()
频繁。在一段时间后,我得到这个除了
当它被调用。或者在它调用该方法的任何其他地方。我看到建议的SOF的解决方案,遗憾的是似乎没有为我工作。即使我叫 mLocationClient.connect()
,也不能保证它会立即连接,纠正我,如果我错了。我该怎么解决这个问题呢?
案例R.id.btnContinue:的
gpsLocationDailog.cancel();
INT isGooglePlayServiceAvilable = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getApplicationContext());
如果(isGooglePlayServiceAvilable == ConnectionResult.SUCCESS){
/ ** thorws低劣expectiosn ** /
mLocationClient.connect();
尝试 {
mLocationClient.requestLocationUpdates(要求,这一点);
mCurrentLocation = mLocationClient.getLastLocation();
fireQueryToGetTheResponse(纬度,经度);
rl.setVisibility(View.VISIBLE);
mDrawerLayout.setVisibility(View.GONE);
mSlidingUpPanelLayout.setVisibility(View.GONE);
}赶上(IllegalStateException异常E){
mLocationClient.connect();
Log.e(TAG,等待的onConnect被称为);
}
} 其他 {
GooglePlayServicesUtil.getErrorDialog(
isGooglePlayServiceAvilable,
SqueakeeMapListViewPager.this,0).show();
}
打破;
和这是所提出的例外:
java.lang.IllegalStateException:未连接。调用connect(),并等待onConnected()被调用。
在com.google.android.gms.internal.de.bc(来源不明)
在com.google.android.gms.internal.ez.a(来源不明)
在com.google.android.gms.internal.ez $ c.bc(来源不明)
在com.google.android.gms.internal.ey.requestLocationUpdates(来源不明)
在com.google.android.gms.internal.ez.requestLocationUpdates(来源不明)
在com.google.android.gms.internal.ez.requestLocationUpdates(来源不明)
在com.google.android.gms.location.LocationClient.requestLocationUpdates(来源不明)
在org.application.app.squeakee.SqueakeeMapListViewPager.onClick(SqueakeeMapListViewPager.java:1936)
在android.view.View.performClick(View.java:4475)
在android.view.View $ PerformClick.run(View.java:18786)
在android.os.Handler.handleCallback(Handler.java:730)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5493)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1209)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
在dalvik.system.NativeStart.main(本机方法)
我有一个类似的错误,基本上,什么说的previous评论能够解决您的问题,是的。 如果你没有跟踪你的错误,它会在此报告:
mLocationClient.requestLocationUpdates(请求,这一点);
原因是,当你调用API方法的客户端未连接。这就是为什么previous答案工作得很好,因为基本上他的所作所为是开始的回调位置更新。
当你这样做:
mLocationClient.connect();
您的客户端将不会立即连接,但在code将保持正在运行,当你问你尚未连接locationUpdates(仍能工作就可以了,它需要它的时候),所以它崩溃。此外,当你做.connect(),您将基本激活onConnected()回调,所以如果你code您locationUpdates里面要求,那么你基本上可以解决大部分的错误。
另外,你说,你有很多的要求,并只,有时会出现此错误。对于这一点,你没有提供足够code,但我认为我可以承担错误发生的原因方式/当您取消请求,并重新激活它们(你的方法的onStop(),在onPause(),onResume ()和ONSTART())。当您暂停您的应用程序,你应该断开客户端,但你应该确保,当你恢复它,你再重新连接,所以也许只是做了
mLocationClient.connect();
在onResume(内部),而且可能解决您的一些其他问题(再次,你没有提供code,也许你的编码是正确的了,但对于有这个问题,其他的读者,这可能是一个建议,解决这个问题)。
这是有点晚了答案,但希望这有助于社会的其余部分。
最好的问候。
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$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
I had a similar error, and basically, what was said on the previous comment will resolve your problem yes. If you did trace your error, it would report here:
mLocationClient.requestLocationUpdates(REQUEST, this);
The reason is that the client isn't connected when you call that API method. And that is why the previous answer works just fine, because basically what he did was to start the location updates on the callback.
When you do this:
mLocationClient.connect();
your client won't immediately connect but the code will kept being run, and when you ask locationUpdates you are not connected yet (it is still working on it, it takes it's time), so it crashes. Also, when you do the .connect() you will basically activate the onConnected() callback, so if you code your locationUpdates request inside it, then you basically will solve most of your errors.
Also, you said that you have a lot of requests and only sometimes this error occurs. For that, you didn't provide enough code, but I think I can assume the error happens because of the way/when you cancel your requests and re-activate them (your methods onStop(), onPause(), onResume() and onStart() ). When you pause your app, you should disconnect the client, but you should make sure that when you resume it, you reconnect it again, so maybe just do the
mLocationClient.connect();
inside the onResume() and that possibly fixes some of your other problems (once again, you didn't provide that code, maybe you are coding it right already, but for some other reader that has this problem, this might be a suggestion to fix it).
It's kinda late answer, but hope this helps the rest of the community.
Best regards.
这篇关于未连接。呼叫连接或等待onConnected()被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!