Note that there are some explanatory texts on larger screens.

plurals
  1. POListView: Null pointer exception
    primarykey
    data
    text
    <p>Good day. I'm having some issues with my android project specifically listview. I tried searching for other information here in this site, and implemented some of the answers. However, it is still not working.</p> <p>The error specifically is </p> <blockquote> <p>NullPointerException at line 76 at MainActivity</p> </blockquote> <p>Here is the code of my MainActivity</p> <pre><code>import java.util.ArrayList; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; public class MainActivity extends Activity { final ArrayList&lt;String&gt; studentName = new ArrayList&lt;String&gt;(); ArrayAdapter&lt;String&gt; aa; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView myList = (ListView) findViewById(R.id.listName); aa = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, studentName); myList.setAdapter(aa); //droid.R.id.list; //add Button bAdd = (Button) findViewById(R.id.addstudent); bAdd.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { startActivity(new Intent("android.intent.action.ADDSTUDENTS")); } }); //edit Button bEdit = (Button) findViewById(R.id.editstudent); bEdit.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View x) { startActivity(new Intent("android.intent.action.EDITSTUDENTS")); } }); //edit Button bDelete = (Button) findViewById(R.id.deletestudent); bDelete.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View x) { startActivity(new Intent("android.intent.action.DELETESTUDENTS")); } }); } public ArrayList&lt;String&gt; getArray(){ return studentName; } public void notifyArray(){ aa.notifyDataSetChanged(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>and line 76 by the way is</p> <pre><code>aa.notifyDataSetChanged(); </code></pre> <p>Here is my code for the AddStudents class</p> <pre><code>import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class AddStudents extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.add_student); Button bAddStudents = (Button) findViewById(R.id.add); final EditText et = (EditText) findViewById(R.id.student_name); bAddStudents.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { MainActivity as = new MainActivity(); as.getArray().add(et.getText().toString()); as.notifyArray(); finish(); } }); Button bBack = (Button) findViewById(R.id.backadd); bBack.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { finish(); } }); } } </code></pre> <p>and the xml part with the list view is </p> <pre><code> &lt;ListView android:id="@+id/listName" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" &gt; &lt;/ListView&gt; </code></pre> <p>I hope you can help me cause I want to also learn what my mistakes are. I can add other information if you want. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload