Android 不幸的是,在ADT&x27;应用程序名称';停止
我的代码是activity_show_location.xmlAndroid 不幸的是,在ADT&x27;应用程序名称';停止,android,runtime-error,Android,Runtime Error,我的代码是activity_show_location.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orie
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="5dip"
android:text="@string/lat"
android:textSize="20sp" >
</TextView>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/unkwn"
android:textSize="20sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="5dip"
android:text="@string/lon"
android:textSize="20sp" >
</TextView>
<TextView
android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/unkwn"
android:textSize="20sp" >
</TextView>
</LinearLayout>
</LinearLayout>
当我在ADT eclipse logcat中运行时
这是我的日志显示:
03-20 07:44:56.383: W/Trace(871): Unexpected value from nativeGetEnabledTags: 0
03-20 07:44:56.383: W/Trace(871): Unexpected value from nativeGetEnabledTags: 0
03-20 07:44:56.783: W/Trace(871): Unexpected value from nativeGetEnabledTags: 0
03-20 07:44:56.783: W/Trace(871): Unexpected value from nativeGetEnabledTags: 0
03-20 07:44:57.343: D/AndroidRuntime(871): Shutting down VM
03-20 07:44:57.343: W/dalvikvm(871): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
03-20 07:44:57.373: E/AndroidRuntime(871): FATAL EXCEPTION: main
03-20 07:44:57.373: E/AndroidRuntime(871): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.locationapi/com.example.locationapi.ShowLocationActivity}: java.lang.IllegalArgumentException: invalid provider: null
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.os.Looper.loop(Looper.java:137) 03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-20 07:44:57.373: E/AndroidRuntime(871): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 07:44:57.373: E/AndroidRuntime(871): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 07:44:57.373: E/AndroidRuntime(871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-20 07:44:57.373: E/AndroidRuntime(871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-20 07:44:57.373: E/AndroidRuntime(871): at dalvik.system.NativeStart.main(Native Method) 03-20 07:44:57.373: E/AndroidRuntime(871): Caused by: java.lang.IllegalArgumentException: invalid provider: null
03-20 07:44:57.373: E/AndroidRuntime(871): at android.location.LocationManager.checkProvider(LocationManager.java:1594)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1138)
03-20 07:44:57.373: E/AndroidRuntime(871): at com.example.locationapi.ShowLocationActivity.onCreate(ShowLocationActivity.java:32)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.Activity.performCreate(Activity.java:5104)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-20 07:44:57.373: E/AndroidRuntime(871): ... 11 more
03-20 07:45:39.193: I/Process(871): Sending signal. PID: 871 SIG: 9
当emulator以“不幸的是LocationAPI已停止”的方式运行时,我得到了答案。请告诉我解决方案。查看这里的日志就是调试
07:44:57.373: E/AndroidRuntime(871): Caused by: java.lang.IllegalArgumentException: invalid provider: null
03-20 07:44:57.373: E/AndroidRuntime(871): at android.location.LocationManager.checkProvider(LocationManager.java:1594)
03-20 07:44:57.373: E/AndroidRuntime(871): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1138)
03-20 07:44:57.373: E/AndroidRuntime(871): at com.example.locationapi.ShowLocationActivity.onCreate(ShowLocationActivity.java:32)
所以在ShowLocationActivity.java:32
Location location = locationManager.getLastKnownLocation(provider);
您提供的提供程序
基本上为空。所以您可能需要检查它为空的可能原因
以下是您应该检查的项目列表:
latitudeField.setText("Location not available.");
longitudeField.setText("Location not available.");
这也不是个好主意
尝试使用
AsyncTask
检查您没有在模拟器中传递位置,要在模拟器中测试gps位置,您需要使用DDMS传递值
下面是你如何做到这一点的:
让我知道它是否有效java.lang.IllegalArgumentException:无效提供程序:NullU是否可以修改代码以尽可能运行。同样的问题也会出现“不幸的是,appname已停止”
latitudeField.setText("Location not available.");
longitudeField.setText("Location not available.");