SimpleCursorAdapterを介してデータベースからリストビューを取り込もうとしていますが、エラーが発生します。 原因:java.lang.IllegalArgumentException:列 '_id'が存在しませんandroid SimpleCursorAdapterはデータベースからリストビューを取り込みます
ここに私のリストビューを含む私のBlistActivityです。
public class BListActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blist);
MyDBHandler myDBHandler = new MyDBHandler(this,null,3);
ListView listView = (ListView) findViewById(R.id.blistView);
Cursor cursor = myDBHandler.showAllRecords();
String[] columnNames = new String[]{"name_number"};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
cursor,
columnNames,
new int[]{android.R.id.text1});
listView.setAdapter(adapter);
}
}
ここはこのアクティビティのXMLコードです。
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.haroon.vuultimateblocker.BListActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/blistView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:choiceMode="multipleChoice"/>
</RelativeLayout>
私はlistViewをmultiplechoiceとして指定する必要があることにも言及しておく必要があります。