gpt4 book ai didi

java - 带有 Google Play 位置服务的应用程序在启动时崩溃

转载 作者:行者123 更新时间:2023-12-01 12:54:03 25 4
gpt4 key购买 nike

解决后this problem昨天我的代码中不再有语法错误。但是,当我在手机上启动应用程序时,它立即崩溃。我不确定错误来自哪里,我认为如果我发布所有内容,代码太多了,所以我将首先发布 logcat,如果有人可以缩小错误范围,我将发布代码的相应部分。

06-03 19:18:34.288: D/AndroidRuntime(22511): Shutting down VM

06-03 19:18:34.288: W/dalvikvm(22511): threadid=1: thread exiting with uncaught exception (group=0x41532ba8)

06-03 19:18:34.288: E/AndroidRuntime(22511): FATAL EXCEPTION: main

06-03 19:18:34.288: E/AndroidRuntime(22511): Process: com.axelfiedler.stayup, PID: 22511

06-03 19:18:34.288: E/AndroidRuntime(22511): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.axelfiedler.stayup/com.axelfiedler.stayup.MainActivity}: java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.ActivityThread.access$800(ActivityThread.java:135)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.os.Handler.dispatchMessage(Handler.java:102)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.os.Looper.loop(Looper.java:136)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.ActivityThread.main(ActivityThread.java:5017)

06-03 19:18:34.288: E/AndroidRuntime(22511): at java.lang.reflect.Method.invokeNative(Native Method)

06-03 19:18:34.288: E/AndroidRuntime(22511): at java.lang.reflect.Method.invoke(Method.java:515)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

06-03 19:18:34.288: E/AndroidRuntime(22511): at dalvik.system.NativeStart.main(Native Method)

06-03 19:18:34.288: E/AndroidRuntime(22511): Caused by: java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.google.android.gms.internal.ff.bT(Unknown Source)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.google.android.gms.internal.hc.a(Unknown Source)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.google.android.gms.internal.hc$c.bT(Unknown Source)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.google.android.gms.internal.hb.getLastLocation(Unknown Source)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.google.android.gms.internal.hc.getLastLocation(Unknown Source)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.google.android.gms.location.LocationClient.getLastLocation(Unknown Source)

06-03 19:18:34.288: E/AndroidRuntime(22511): at com.axelfiedler.stayup.MainActivity.onCreate(MainActivity.java:223)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.Activity.performCreate(Activity.java:5231)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

06-03 19:18:34.288: E/AndroidRuntime(22511): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

06-03 19:18:34.288: E/AndroidRuntime(22511): ... 11 more

06-03 19:19:56.736: D/AndroidRuntime(23049): Shutting down VM

06-03 19:19:56.736: W/dalvikvm(23049): threadid=1: thread exiting with uncaught exception (group=0x41532ba8)

06-03 19:19:56.736: E/AndroidRuntime(23049): FATAL EXCEPTION: main

06-03 19:19:56.736: E/AndroidRuntime(23049): Process: com.axelfiedler.stayup, PID: 23049

06-03 19:19:56.736: E/AndroidRuntime(23049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.axelfiedler.stayup/com.axelfiedler.stayup.MainActivity}: java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.ActivityThread.access$800(ActivityThread.java:135)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.os.Handler.dispatchMessage(Handler.java:102)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.os.Looper.loop(Looper.java:136)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.ActivityThread.main(ActivityThread.java:5017)

06-03 19:19:56.736: E/AndroidRuntime(23049): at java.lang.reflect.Method.invokeNative(Native Method)

06-03 19:19:56.736: E/AndroidRuntime(23049): at java.lang.reflect.Method.invoke(Method.java:515)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

06-03 19:19:56.736: E/AndroidRuntime(23049): at dalvik.system.NativeStart.main(Native Method)

06-03 19:19:56.736: E/AndroidRuntime(23049): Caused by: java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.google.android.gms.internal.ff.bT(Unknown Source)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.google.android.gms.internal.hc.a(Unknown Source)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.google.android.gms.internal.hc$c.bT(Unknown Source)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.google.android.gms.internal.hb.getLastLocation(Unknown Source)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.google.android.gms.internal.hc.getLastLocation(Unknown Source)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.google.android.gms.location.LocationClient.getLastLocation(Unknown Source)

06-03 19:19:56.736: E/AndroidRuntime(23049): at com.axelfiedler.stayup.MainActivity.onCreate(MainActivity.java:223)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.Activity.performCreate(Activity.java:5231)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

06-03 19:19:56.736: E/AndroidRuntime(23049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

06-03 19:19:56.736: E/AndroidRuntime(23049): ... 11 more

编辑:这就是我在 onCreate() 中调用 connect() 函数的方式

    mLocationClient = new LocationClient(this, this, this);
mLocationClient.connect();
mCurrentLocation = mLocationClient.getLastLocation();

最佳答案

看这一行:调用 connect() 并等待 onConnected() 被调用。

我认为您在位置客户端真正连接之前请求更新。
当您调用 locationClient.connect() 时,您必须等待 onConnected() 上的答案这是您必须重写的方法。

编辑:
我在您更新的问题中看到了问题。你必须打电话
mCurrentLocation = mLocationClient.getLastLocation();
onConnected()内。

在您的 Activity 或 Fragment 中,添加 implements ConnectionCallbacks,
并重写方法 onConnected()onDisconnected()

祝你好运。

关于java - 带有 Google Play 位置服务的应用程序在启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24021518/

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