Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';无法使用gps获取当前位置(应用程序崩溃)_Android_Gps - Fatal编程技术网

Android Can';无法使用gps获取当前位置(应用程序崩溃)

Android Can';无法使用gps获取当前位置(应用程序崩溃),android,gps,Android,Gps,当我在emulator上运行应用程序时一切正常,但当我在手机上运行应用程序(三星galaxy mini)时,我的应用程序崩溃了(我不知道为什么,我打开了gps和互联网) 代码: convertLoc是我创建的将位置转换为地质点的函数 在真实设备上运行时更新Logcat: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) at android.app.ActivityThread.handle

当我在emulator上运行应用程序时一切正常,但当我在手机上运行应用程序(三星galaxy mini)时,我的应用程序崩溃了(我不知道为什么,我打开了gps和互联网)

代码:

convertLoc
是我创建的将位置转换为地质点的函数

在真实设备上运行时更新Logcat:

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:130) 
at android.app.ActivityThread.main(ActivityThread.java:3687) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:507) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 
at dalvik.system.NativeStart.main(Native Method)  
Caused by: java.lang.NullPointerException 
at tim_atm.namespace.atm_atmogan.convertLoc(atm_atmogan.java:115) 
at tim_atm.namespace.atm_atmogan.onCreate(atm_atmogan.java:146) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
更新布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.google.android.maps.MapView
        android:id="@+id/map_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="0rMwFsILEdg4813dweucAH5iRKJHGozQs8FFvzQ" 

        />
</RelativeLayout>


请检查
mlocManager.getLastKnownLocation()
是否返回非空值。

getLastKnownLocation不保证您将获得位置。您应该监听位置更改,然后将该位置用作备份计划。您可能希望使用其他参数尝试getLastKnownLocation


此外,您可能需要删除Map API密钥;)

把你的错误放在你的问题中…当应用程序崩溃时,LogCat输出是什么?当我在emulator上运行应用程序时。。。一切都好。。不是错误。当我在我的真实手机(三星galaxy mini)上运行应用程序时,应用程序崩溃…在你的设备上运行应用程序,而应用程序仍连接到你的电脑。当应用程序崩溃时,请复制并粘贴LogCat输出。我使用linux并在我的电脑上运行应用程序。我无法选择我的手机:(.你能告诉我如何修复它吗?我不知道为什么方法getLastKnownLocation()返回空值…我正在实际设备上测试。你能告诉我如何解决我的问题吗?启用你的gps并打开,以便设备可以访问gps卫星并存储一个位置,也称为“mapController.animateTo(convertLoc)”(location));“如果位置为空,则使用一些默认值,并从侦听器的onLocationChanged()方法调用”mapController.animateTo(convertLoc(location));“。我已启用gps、internet、使用无线网络、使用gps卫星:(可能是设备无法从办公室访问gps卫星。请尝试在户外外出,看看是否可以访问gps卫星。您还可以使用以下应用程序在真实设备上捕获日志
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.google.android.maps.MapView
        android:id="@+id/map_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="0rMwFsILEdg4813dweucAH5iRKJHGozQs8FFvzQ" 

        />
</RelativeLayout>