Search code examples
androidbackwards-compatibilityandroid-4.3-jelly-bean

app crashes on android 4.3


I got an issue with an android app I'm trying to develop. When I test it in an emulator with android 4.4.2 (the target sdk version), everything works fine. But when I run the same code in an emulator with the same settings but android 4.3 instead, the app crashes almost immediately with the catlog error below.

Using the android lint in eclipse (right click on project, "Android tools" > "Run lint: check for common error"), I cannot find any code that doesn't correspond with the minSdkVersion (16).

Anyone got suggestions what's going wrong?

Catlog error:

    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

Solution

  • I found the problem thanks to @codeMagic and @Chris Stratton. Line 167 in my code was

        if(!username.equals(null)){
    

    I changed that to

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

    => Problem solved!