Has someone already had this problem: - I'm initializing a LocationClient, with ConnectionCallbacks and so on... - Then, I call "connect()" on it. - In my "onConnected" method, I call myLocationClient.getLastLocation(), which makes the app crash on some people devices, with exception :
"Fatal Exception: java.lang.IllegalStateException Not connected. Call connect() and wait for onConnected() to be called."
Any idea?
Here's some part of the code:
myLocationClient = new LocationClient(this, new ConnectionCallbacks() {
@Override
public void onDisconnected() {
//Do some stuff here
}
@Override
public void onConnected(Bundle arg0) {
if(myLocationClient.getLastLocation() != null) {
//Do some other stuff here
}
}
}, new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult arg0) {
//Do other stuff here
}
});
myLocationClient.connect();
The app crashes on the first line of the "onConnected" method.
For people who want the stack here it is:
java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
at com.google.android.gms.internal.k.B()
at com.google.android.gms.internal.bh.a()
at com.google.android.gms.internal.bh$c.B()
at com.google.android.gms.internal.bg.getLastLocation()
at com.google.android.gms.internal.bh.getLastLocation()
at com.google.android.gms.location.LocationClient.getLastLocation()
at com.myAppPackage.onConnected(AroundMeActivity.java:321)
at com.google.android.gms.internal.k.y()
at com.google.android.gms.internal.k$f.a()
at com.google.android.gms.internal.k$f.a()
at com.google.android.gms.internal.k$b.D()
at com.google.android.gms.internal.k$a.handleMessage()
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Method.java)
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(NativeStart.java)