0

I get a NullPointerException in production that I cannot reproduce locally. The stack trace is meaningless to me, because it references a NullPointerException to a member declaration.

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3430)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3614)
  at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:5527)
  at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:5418)
  at android.app.servertransaction.ActivityRelaunchItem.execute (ActivityRelaunchItem.java:69)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2199)
  at android.os.Handler.dispatchMessage (Handler.java:112)
  at android.os.Looper.loop (Looper.java:216)
  at android.app.ActivityThread.main (ActivityThread.java:7625)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
Caused by: java.lang.NullPointerException: 
  at org.catrobat.paintroid.MainActivity.onCreate (MainActivity.java:122)
  at android.app.Activity.performCreate (Activity.java:7458)
  at android.app.Activity.performCreate (Activity.java:7448)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1286)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3409)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3614)
  at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:5527)
  at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:5418)
  at android.app.servertransaction.ActivityRelaunchItem.execute (ActivityRelaunchItem.java:69)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2199)
  at android.os.Handler.dispatchMessage (Handler.java:112)
  at android.os.Looper.loop (Looper.java:216)
  at android.app.ActivityThread.main (ActivityThread.java:7625)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)

It is strange to me because the NullPointerExeption does not give a line where where I use a variable, rather it points at the declaration of a variable.

public class MainActivity extends AppCompatActivity {
    public static final String TAG = MainActivity.class.getSimpleName();
    public ToolReference toolreference;   <---- NullpointerException at this line ?!?! (this is MainActivity:122)

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.MyTheme);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activiy_main);

    toolRefence = new ToolReference();
    ...
    }

    ...
}

The code snippet is a little bit simplified. Full code here. I do understand why NullPointerExceptions happen, but it never happened to me that it says to me the variable declaration is a problem

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
tscheppe
  • 588
  • 5
  • 18

0 Answers0