Java SQLite列“\u id”不存在
应用程序:我有一个应用程序,可以创建多台机器,其中包括: id、名称和位置 每台机器我都要让用户输入收入 身份证、票据、日期、货币、机器 问题:java.lang.IllegalArgumentException:列'\u id'不存在,而在DBHelper中显然存在 我尝试过:卸载应用程序,用ADM删除DB,升级DB版本 我的问题:我错过了什么 如果你需要任何其他课程或有任何反馈,请毫不犹豫地放纵我 数据库助手 列表适配器 错误Java SQLite列“\u id”不存在,java,listview,android-sqlite,android-cursoradapter,Java,Listview,Android Sqlite,Android Cursoradapter,应用程序:我有一个应用程序,可以创建多台机器,其中包括: id、名称和位置 每台机器我都要让用户输入收入 身份证、票据、日期、货币、机器 问题:java.lang.IllegalArgumentException:列'\u id'不存在,而在DBHelper中显然存在 我尝试过:卸载应用程序,用ADM删除DB,升级DB版本 我的问题:我错过了什么 如果你需要任何其他课程或有任何反馈,请毫不犹豫地放纵我 数据库助手 列表适配器 错误 正如Javadoc所述: 游标必须包含名为_id的列,否则此类将
正如Javadoc所述: 游标必须包含名为_id的列,否则此类将不会 工作 因此,必须将_id添加到投影中,以便生成的光标将具有该列。例如:
Cursor cursor = db.rawQuery("SELECT _id, note, date FROM income WHERE machines_id = "+machinesId+"", null);
可能重复为什么它是重复的?你能详述你的声明吗?
public class MachineInfo extends AppCompatActivity {
private TextView mLocation, mMoney, mNotes;
private DBHelpter mDBHelpter;
private ListView mNotesList;
private FloatingActionButton mFAB;
private SQLiteDatabase db;
private Cursor mCursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_machine_info);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDBHelpter = new DBHelpter(getApplicationContext());
db = mDBHelpter.getWritableDatabase();
mLocation = (TextView) findViewById(R.id.tvLocation);
mMoney = (TextView) findViewById(R.id.tvMoney);
mNotes = (TextView) findViewById(R.id.tvNotes);
mFAB = (FloatingActionButton) findViewById(R.id.fabAddIncome);
mNotesList = (ListView) findViewById(R.id.lvNotes);
SharedPreferences mSharedPreferences = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
Long machines_id = mSharedPreferences.getLong("machines_id", 0);
double total_amount = mDBHelpter.getIncomeOfMachine(machines_id);
mMoney.setText(String.format("%.3f",total_amount));
String location = mSharedPreferences.getString("location", null);
mLocation.setText(location);
mCursor = db.rawQuery("SELECT note, date FROM income WHERE machines_id = "+machines_id+"",null);
ListAdapter adapter = new ListAdapter(this, mCursor);
mNotesList.setAdapter(adapter);
db.close();
mFAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), IncomeCreation.class);
startActivity(i);
}
});
}
public class ListAdapter extends CursorAdapter {
public ListAdapter(Context context, Cursor c) {
super(context, c);
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.notes_list, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
DBHelpter mDBHelper = new DBHelpter(context);
SQLiteDatabase db = mDBHelper.getWritableDatabase();
TextView mNote = (TextView) view.findViewById(R.id.tvNote);
TextView mNotesDate = (TextView) view.findViewById(R.id.tvNoteDate);
String note = cursor.getString(cursor.getColumnIndex("note"));
String date = cursor.getString(cursor.getColumnIndex("date"));
mNote.setText(note);
mNotesDate.setText(date);
}
java.lang.RuntimeException: Unable to start activity ComponentInfo{tech.destinum.machines/tech.destinum.machines.MachineInfo}: java.lang.IllegalArgumentException: column '_id' does not exist
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:333)
at android.widget.CursorAdapter.init(CursorAdapter.java:180)
at android.widget.CursorAdapter.<init>(CursorAdapter.java:128)
at tech.destinum.machines.ListAdapter.<init>(ListAdapter.java:0)
at tech.destinum.machines.MachineInfo.onCreate(MachineInfo.java:62)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Cursor cursor = db.rawQuery("SELECT _id, note, date FROM income WHERE machines_id = "+machinesId+"", null);