0

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
user1834095
  • 5,332
  • 2
  • 20
  • 38
  • What are you doing in `loginPopup`? Specifically at line 167 – codeMagic Aug 01 '14 at 20:56
  • it's always the same question... – PKlumpp Aug 01 '14 at 20:57
  • 1
    Show the code of the loginPopup method and identify which line is line 167 of the MainActivity.java file. Also include the declaration and initialization of any variables or fields referenced in it. – Chris Stratton Aug 01 '14 at 20:58
  • You forgot to read the stacktrace. If you don't know how to I'd suggest that you work through a debugging tutorial for android. A linter is for compile-time exceptions. You have a runtime exception. – keyser Aug 01 '14 at 21:00
  • Whats on your MainActivity.java line 61? – Jorgesys Aug 01 '14 at 21:01
  • The problem is definitely with MainActivity.java, in onCreate() and loginPopup(), and the main cause is probably your layout for MainActivity, looks like sth can't render. – Farhad Aug 01 '14 at 21:07
  • @codeMagic and Chris Stratton, the problem was indeed line 167. How did you know that line was the rootcause (and not any of the other ones reported)? – user1834095 Aug 02 '14 at 12:00
  • 1
    @user1834095 http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors – nhaarman Aug 02 '14 at 12:50
  • @user1834095 it's typically the first line which references your code, in a situation like this. Though, sometimes you may need to dig deeper. Anyway, the linked post should help you in debugging. – codeMagic Aug 02 '14 at 14:16

1 Answers1

0

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!

user1834095
  • 5,332
  • 2
  • 20
  • 38