java.lang.RuntimeException: Unable to start activity ComponentInfo{com.asad.android.canieatthis/com.asad.android.canieatthis.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.asad.android.canieatthis.Food.getUpc()' on a null object reference

Stack Overflow | Asad Aizaz | 5 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Output works while debugging but returns with runtime error when running

    Stack Overflow | 5 months ago | Asad Aizaz
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.asad.android.canieatthis/com.asad.android.canieatthis.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.asad.android.canieatthis.Food.getUpc()' on a null object reference

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke virtual method 'java.lang.String com.asad.android.canieatthis.Food.getUpc()' on a null object reference

      at com.asad.android.canieatthis.MainActivity.onCreate()
    2. com.asad.android
      MainActivity.onCreate
      1. com.asad.android.canieatthis.MainActivity.onCreate(MainActivity.java:62)
      1 frame
    3. Android Platform
      ActivityThread.performLaunchActivity
      1. android.app.Activity.performCreate(Activity.java:6876)
      2. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
      3. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
      3 frames