Android: arrayAdapter 抛出空指针异常?

Android: arrayAdapter throwing null pointer exception?

阵列适配器出现问题。

这是我的 lessonNotesList 中的内容 class:

     mydb = new DBHelper(this);
    //Creating an ArrayList of contacts data
    ArrayList array_list = mydb.getAllLessonNotes();
    //Creating an Array Adapter to manipulate the contacts data into a ListView
    ArrayAdapter arrayAdapter = new ArrayAdapter(this,R.layout.list_layout, array_list);
    //Adding the contacts to the list view.
    lessonNote = (ListView)findViewById(R.id.listView1);
    lessonNote.setAdapter(arrayAdapter);
    //Setting an onClickListener to process the user's actions
    lessonNote.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub

            //Prepare the data from the ListView item to be passed to new activity
            //arg2 is increased by one as its a zero based index but the contacts table in the database works of a base index of 1

            int id_To_Search = VALUE;
            //Bundle extras = getIntent().getExtras();
            Bundle dataBundle = new Bundle();
            dataBundle.putInt("id", id_To_Search);
            Log.d("Id is ^&*: ", String.valueOf(id_To_Search));
            //Create a new intent to open the DisplayContact activity
            Intent intent = new Intent(getApplicationContext(), com.example.ltss.dyslexia.app.LessonNotes.class);
            intent.putExtras(dataBundle);
            startActivity(intent);
        }
    });

DBHelper class:

public ArrayList getAllLessonNotes()
{
    ArrayList array_list = new ArrayList();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res =  db.rawQuery( "select * from "+TABLE_LESSON_NOTES, null);
    res.moveToFirst();
    while(res.isAfterLast() == false)
    {
        array_list.add(res.getString(res.getColumnIndex(DATE)));
        res.moveToNext();
    }
    return array_list;
}

代码因 NULL 指针异常而崩溃:

lessonNote.setAdapter(arrayAdapter);

知道为什么会这样吗? 我试过调试,调试器告诉我 arrayAdatper 包含 1 个条目,因为它应该

我在不同的页面上使用了几乎相同的代码,并且 100% 正常工作..

欢迎提出任何建议!

谢谢

你确定那条线吗?

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

似乎在您的布局 XML 中,没有视图具有 "listView1" id。