[Solved] java.lang.RuntimeException: Unable to instantiate activity ComponentInfo in android camera app


Caused by: java.lang.NullPointerException
  at android.app.Activity.findViewById(Activity.java:1794)
  at firstapp.boysjoys.com.waste.MainActivity.<init>(MainActivity.java:102)

You’re calling findViewById() too early, in activity <init> phase that includes e.g. member variable initialization.

You can only call activity methods like findViewById() in onCreate() or later in the activity lifecycle.

Move the findViewById() call to onCreate() to get rid of the NPE. Put it after setContentView() so that it can actually return a non-null value.

solved java.lang.RuntimeException: Unable to instantiate activity ComponentInfo in android camera app