0

This is my intent:

Intent intentPay = new Intent(getApplicationContext(), PayScreenActivity.class);
                    intentPay.putExtra(PayScreenActivity.CHAVE_COMIDA, idRestaurante);
                    intentPay.putStringArrayListExtra("LISTA_COMIDAS", convertedSelected);
                    intentPay.putExtra("COMIDAS", comidasPedidasObj);
                    startActivity(intentPay);

And this is me getting values:

public class PayScreenActivity extends AppCompatActivity {

public static final String CHAVE_COMIDA = "COMIDA";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pay_screen);

    final Intent intent = getIntent();
    ArrayList<String> listaComidas = intent.getStringArrayListExtra("LISTA_COMIDAS");
    ArrayList<Comida> listaFinal = intent.getParcelableExtra("COMIDAS");

}

}

comidasPedidasObj have 3 values

And my error:

But it comes Null

David
  • 1
  • I believe that you already know that debugging on some line did not execute code for that particular line - if so there is some kind of issue, if not try stepping to the next instruction and then check the value on that list. (Also try putting images to your question directly) – itwasntme Jan 19 '20 at 19:22
  • Hi, welcome to SO, can you share more detail? what is the `comidasPedidasObj` value? – javadroid Jan 19 '20 at 19:25
  • Hi, its this "public ArrayList comidasPedidasObj = new ArrayList<>();" @javadroid – David Jan 19 '20 at 19:26
  • I have already stepped to next instruction the value is null. (Its my first post i don't know how to do that, but i will try on next one) @itwasntme – David Jan 19 '20 at 19:37
  • Sounds like `comidasPedidasObj` is not a `getParcelableExtra`, does it not give you a type check error log in Logcat? – EpicPandaForce Jan 19 '20 at 19:43
  • No, the only error I got its when i try to access my 'listaFinal' its says 'Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.isEmpty()' on a null object reference' @EpicPandaForce – David Jan 19 '20 at 19:49

1 Answers1

0

Use this:

 final Intent intent = getIntent();
ArrayList<String> listaComidas = 
   intent.getStringArrayListExtra("LISTA_COMIDAS");
 ArrayList<Comida> listaFinal = 
intent.getExtras("COMIDAS");

You are passing extras to your intent but u arent extracting those intents data. Try the above code pls.

Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20