java.lang.IllegalArgumentException: column '_id' does not exist
package com.example.user.acconting;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class MainActivity2 extends AppCompatActivity implements AdapterView.OnItemClickListener{
String db_name="db_name";
String tb_name="tb_name";
static final int MAX=8;
static final String[] FROM=new String[] {"amount","idcategory","date"};
SQLiteDatabase db;
Cursor cur;
SimpleCursorAdapter adapter;
EditText etDate,etAmount,etCategory;
Button btInsert,btUpdate,btDelete,btQuery;
ListView lv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
etDate=(EditText)findViewById(R.id.editText3);
etAmount=(EditText)findViewById(R.id.editText5);
etCategory=(EditText)findViewById(R.id.editText4);
btInsert=(Button)findViewById(R.id.button);
btDelete=(Button)findViewById(R.id.button1);
btUpdate=(Button)findViewById(R.id.button2);
btQuery=(Button)findViewById(R.id.button3);
lv=(ListView)findViewById(R.id.lv);
db=openOrCreateDatabase(db_name, Context.MODE_PRIVATE,null);
String createTable="CREATE TABLE IF NOT EXISTS "+tb_name
+ "(_id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "amount VARCHAR(16),"
+ "category VARCHAR(32),"
+ "date VARCHAR(32))";
db.execSQL(createTable);
addDate("100", "生活用品", "20170915");
addDate("100","生活用品","20170915");
cur=db.rawQuery("SELECT * FROM tb_name",null);
adapter=new SimpleCursorAdapter(this,R.layout.item,cur,
FROM,
new int[]{R.id.amount,R.id.category,R.id.date},0);
lv=(ListView)findViewById(R.id.lv);
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
}
public void onItemClick (AdapterView<?> parent, View v, int position,long id){
cur.moveToPosition(position);
etAmount.setText(cur.getInt(cur.getColumnIndex(FROM[0])));
etCategory.setText(cur.getString(cur.getColumnIndex(FROM[1])));
etDate.setText(cur.getInt(cur.getColumnIndex(FROM[2])));
}
private void addDate(String amount,String category,String date){
ContentValues cv=new ContentValues(3);
cv.put("amount",amount);
cv.put("category",category);
cv.put("date",date);
db.insert(tb_name,null,cv);
}
}
总显示这个错误: java.lang.IllegalArgumentException: column '_id' does not exist,但我数据库有_id啊,这是为什么?我搜索了一下,也是要加_id,求大佬帮帮忙