gpt4 book ai didi

android - 未连接。调用 Connect 或等待 onConnected() 在 onConnected 内部调用异常?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:55:42 25 4
gpt4 key购买 nike

我为 Google LocationClient API 实现了这个 onConnected 回调:

@Override
public void onConnected(Bundle arg0) {
if (lc != null) {
lastKnownLocation = lc.getLastLocation();
LocationRequest request = new LocationRequest();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setFastestInterval(MIN_TIME_BETWEEN_LOCATION_UPDATES);
request.setSmallestDisplacement(MIN_DISTANCE_BETWEEN_LOCATION_UPDATES);
lc.requestLocationUpdates(request, ll);
}
}

出于某种原因,有时这一行:

lastKnownLocation = lc.getLastLocation();

给我这个异常(exception):

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
at com.google.android.gms.internal.de.bc()
at com.google.android.gms.internal.ez.a()
at com.google.android.gms.internal.ez$c.bc()
at com.google.android.gms.internal.ey.getLastLocation()
at com.google.android.gms.internal.ez.getLastLocation()
at com.google.android.gms.location.LocationClient.getLastLocation()
at com.citylifeapps.cups.helputils.UserLocation.onConnected(UserLocation.java:115)
at com.google.android.gms.internal.de.aZ()
at com.google.android.gms.internal.de$f.a()
at com.google.android.gms.internal.de$f.a()
at com.google.android.gms.internal.de$b.be()
at com.google.android.gms.internal.de$a.handleMessage()
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)

我真的不明白为什么会这样。显然,在运行连接方法并等待 onConnected 回调之后,我正在尝试使用 LocationClient 获取最后一个已知位置,据我了解 onConnected 回调在我有连接时被调用,那么我怎样才能得到 "Not connected ..." 异常呢?有人知道吗?

谢谢。

最佳答案

也许像我一样,您根本没有调用 connect()。尝试包含在 onStart 方法中的调用:

@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}

关于android - 未连接。调用 Connect 或等待 onConnected() 在 onConnected 内部调用异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23032966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com