Null Pointer Exc: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference : <p>I have MainActivity:
public class MainActivity extends Activity {</p>

<pre><code>private ArrayList&lt;Antrenament&gt; listaAntr = new ArrayList&lt;&gt;();

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

    Antrenament a1 = new Antrenament("forta","12/06/2019",50,"Andrei");
    listaAntr.add(a1);

    Button bAdd = (Button) findViewById(R.id.buttonAdd);
    Button bLista = (Button) findViewById(R.id.buttonList);


    bAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), AdaugareAntrenament.class);
            intent.putParcelableArrayListExtra("listaant",listaAntr);
            startActivityForResult(intent,1);

        }
    });


    bLista.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), ListaAntr.class);
            intent.putParcelableArrayListExtra("listaant",listaAntr);
            startActivityForResult(intent,1);
        }
    });


    Intent intent2 = getIntent();
    listaAntr = intent2.getParcelableArrayListExtra("listaantr");


}
</code></pre>

<p>}</p>

<p>I want to send the list of objects Antrenament name listaAntr to AdaugareAntrenament activity, where I want to create a new Antrenament object, add it to the list and then send back the list to mainactivity. This updated list I want to send afterward to ListaAntr Activity, from mainactivity.</p>

<p>AdaugareAntrenament activity:</p>

<p>public class AdaugareAntrenament extends Activity {</p>

<pre><code> ArrayList&lt;Antrenament&gt; listaAntr1=new ArrayList&lt;&gt;();
//private Button add;
 EditText etcateg, etdurata, etinstr,etdata;
List&lt;String&gt; listacateg=new ArrayList&lt;&gt;();
Spinner spinner;

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

    Intent intent = getIntent();
   listaAntr1 = intent.getParcelableArrayListExtra("listaant");

    Button add = findViewById(R.id.buttonSave);
    etdurata=findViewById(R.id.editTextDurata);
    etinstr=findViewById(R.id.editTextInstructor);
    etdata=findViewById(R.id.editTextData);
    spinner=findViewById(R.id.spinner);

    listacateg=new ArrayList&lt;&gt;(Arrays.asList(getResources().getStringArray(R.array.categ)));

    ArrayAdapter&lt;String&gt; adapter=new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item,listacateg);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String categorie,instructor,data;
            int durata;

            durata = Integer.parseInt(etdurata.getText().toString());
            instructor = etinstr.getText().toString().trim();
            data = etdata.getText().toString().trim();
            categorie = spinner.getSelectedItem().toString().trim();



            if(TextUtils.isEmpty(instructor)) {
                etinstr.setError("Introduceti numele instructorului");
                return;
            }

            if(TextUtils.isEmpty(data)) {
                etdata.setError("Introduceti data programarii");
                return;
            }

                Antrenament antr = new Antrenament(categorie, data, durata, instructor);
                listaAntr1.add(antr);
                Intent intent=new Intent(getApplicationContext(), MainActivity.class);
                intent.putParcelableArrayListExtra("listaantr",listaAntr1);

        }
    });

}
</code></pre>

<p>For the moment I get that error when I try to create the Antrenament object.. but this after some changes, because my code doesn't even send the updated list back to main activity.</p>

<p>Current error: </p>

<pre><code> java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference
        at com.example.ancaa.rezolvarerestanta20181.AdaugareAntrenament$1.onClick(AdaugareAntrenament.java:78)
</code></pre>

<p>The error points to the line :     </p>

<pre><code>  listaAntr1.add(antr);
</code></pre>

<p>and ListaAntr Activity: </p>

<p>public class ListaAntr extends Activity {</p>

<pre><code>public ArrayList&lt;Antrenament&gt; listaAntr = new ArrayList&lt;&gt;();
public ListView lv;

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

    lv = (ListView)findViewById(R.id.lista);

    Intent intent = getIntent();
    listaAntr = intent.getParcelableArrayListExtra("listaantr");

    ArrayAdapter&lt;Antrenament&gt; adapter=new ArrayAdapter&lt;Antrenament&gt;(this,android.R.layout.simple_list_item_1,listaAntr);
    lv.setAdapter(adapter);

}
</code></pre>

<p>}</p>

<p>Here the content of the arraylist should be shown as a listview.</p>
