0

Please help my problem in when I want to enter the listview activity that is taking Details from SQL , The app just crash.

09-09 18:25:06.698: E/AndroidRuntime(19913): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raingp.jungle/com.raingp.jungle.FirstActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference

FirstActivity.class

public class FirstActivity extends Activity {

private ListView name_view;
SQLiteDatabase sqdb;

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

    name_view = (ListView)findViewById(R.id.listView1);


    DBHelper mydbhelper = new DBHelper(this);

    try {

        mydbhelper.createDataBase();

    } catch (IOException e) {
        throw new Error("error");
    }

    try {
        mydbhelper.openDataBase();

    } catch (SQLException sql) {

        throw sql;
    }


    sqdb = mydbhelper.getReadableDatabase();

    Cursor c =mydbhelper.readName();
    c.moveToFirst();


    Adapter myAdapter = new Adapter(this, c);
    name_view.setAdapter(myAdapter);


}

and I don't know how to fix it.

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41

1 Answers1

0

From the little information you provided, you probably are trying to set adapter in a null object. In you listview.setAdapter(adapter) your listview object is null.

Mateus Brandao
  • 900
  • 5
  • 9