我有一个Android应用程序但是当我想运行这个应用程序时,模拟器停止了编译:不幸的是Android应用程序已停止
这是Logcat文件:
07-14 14:27:09.867: D/AndroidRuntime(1450): Shutting down VM
07-14 14:27:09.867: W/dalvikvm(1450): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-14 14:27:09.887: E/AndroidRuntime(1450): FATAL EXCEPTION: main
07-14 14:27:09.887: E/AndroidRuntime(1450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.peoplesqlite/com.example.peoplesqlite.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.os.Handler.dispatchMessage(Handler.java:99)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.os.Looper.loop(Looper.java:137)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-14 14:27:09.887: E/AndroidRuntime(1450): at java.lang.reflect.Method.invokeNative(Native Method)
07-14 14:27:09.887: E/AndroidRuntime(1450): at java.lang.reflect.Method.invoke(Method.java:511)
07-14 14:27:09.887: E/AndroidRuntime(1450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-14 14:27:09.887: E/AndroidRuntime(1450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-14 14:27:09.887: E/AndroidRuntime(1450): at dalvik.system.NativeStart.main(Native Method)
07-14 14:27:09.887: E/AndroidRuntime(1450): Caused by: java.lang.NumberFormatException: Invalid int: ""
07-14 14:27:09.887: E/AndroidRuntime(1450): at java.lang.Integer.invalidInt(Integer.java:138)
07-14 14:27:09.887: E/AndroidRuntime(1450): at java.lang.Integer.parseInt(Integer.java:359)
07-14 14:27:09.887: E/AndroidRuntime(1450): at java.lang.Integer.parseInt(Integer.java:332)
07-14 14:27:09.887: E/AndroidRuntime(1450): at java.lang.Integer.<init>(Integer.java:102)
07-14 14:27:09.887: E/AndroidRuntime(1450): at com.example.peoplesqlite.MainActivity.onCreate(MainActivity.java:26)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.Activity.performCreate(Activity.java:5104)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-14 14:27:09.887: E/AndroidRuntime(1450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-14 14:27:09.887: E/AndroidRuntime(1450): ... 11 more
答案 0 :(得分:1)
您将空字符串传递给Integer.parseInt(),在调用该方法之前添加null或空检查。