Я пытаюсь отобразить данные из таблицы базы данных в listView, извлекая данные с помощью курсора, передавая курсор на SimpleCursorAdapter и устанавливая адаптер в listView, как показано ниже. Приложение аварийно завершает работу из-за проблемы в спискеAdapter.setAdapter (адаптер).android listView.setAdapter ошибка с SimpleCursorAdapter
-I подтвердил есть данные в таблице чатов им с помощью
-upon отлова исключения, ex.getMessage была нулевой, но он указал номер строки в качестве одного с listAdapter.setAdapter (адаптер) КОДА:
ChatsActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Conn connection = new Conn();
SQLiteDatabase db = connection.getDB(this, "chats", 1);
//returns readable database
Cursor result = db.rawQuery("SELECT * FROM chats", null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.other,
result,
new String[]{"_id", "lastContent"},
new int[]{R.id.textView1, R.id.textView2});
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
setContentView(listView);
}
}
2 Other.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Main"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="Sub"
android:textAppearance="?android:attr/textAppearanceMedium" /> </RelativeLayout>
Activity_chats.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".ChatsActivity">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" /> </RelativeLayout>
В чем может быть проблема?