应用程序在Android 4.3上崩溃

时间:2014-08-01 20:53:31

标签: android backwards-compatibility android-4.3-jelly-bean

我遇到了一个我正在尝试开发的Android应用程序的问题。当我在一个带有android 4.4.2(目标sdk版本)的模拟器中进行测试时,一切正常。但是当我在具有相同设置的模拟器中运行相同的代码但是安卓4.3时,应用程序几乎立即崩溃,下面是catlog错误。

在eclipse中使用android lint(右键单击项目,“Android工具”>“运行lint:检查常见错误”),我找不到任何与minSdkVersion(16)不对应的代码。登记/>
有人知道出了什么问题吗?

Catlog错误:

    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

1 个答案:

答案 0 :(得分:0)

感谢@codeMagic和@Chris Stratton,我发现了这个问题。我的代码中的第167行是

    if(!username.equals(null)){

我把它改为

    if(username != null && !username.isEmpty()){

=>问题解决了!