我在开发一个安卓应用程序时遇到了一个问题。当我在android 4.4.2(目标sdk版本)的模拟器中测试它时,一切都很好。但是,当我在模拟器中运行相同的代码与相同的设置,但android 4.3代替,应用程序崩溃几乎立即与以下目录错误。
在eclipse中使用android lint(右键单击项目,"android工具">"运行lint:检查常见错误"),我找不到任何与minSdkVersion(16)不对应的代码。
有人知道是哪里出了问题吗?
07-24 12:54:14.592: D/AndroidRuntime(1012): Shutting down VM
07-24 12:54:14.592: W/dalvikvm(1012): threadid=1: thread exiting with uncaught exception (group=0x41465700)
07-24 12:54:14.631: E/AndroidRuntime(1012): FATAL EXCEPTION: main
07-24 12:54:14.631: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.protime360_basics/com.example.protime360_basics.MainActivity}: java.lang.NullPointerException
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.os.Looper.loop(Looper.java:137)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-24 12:54:14.631: E/AndroidRuntime(1012): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:54:14.631: E/AndroidRuntime(1012): at java.lang.reflect.Method.invoke(Method.java:525)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-24 12:54:14.631: E/AndroidRuntime(1012): at dalvik.system.NativeStart.main(Native Method)
07-24 12:54:14.631: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.example.protime360_basics.MainActivity.loginPopup(MainActivity.java:167)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.example.protime360_basics.MainActivity.onCreate(MainActivity.java:61)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.Activity.performCreate(Activity.java:5133)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
07-24 12:54:14.631: E/AndroidRuntime(1012): ... 11 more
我发现了这个问题多亏了@codeMagic和@Chris Stratton。我代码中的第167行是
if(!username.equals(null)){
改成
if(username != null && !username.isEmpty()){
=>问题解决!