Android 由于列不';不存在

Android 由于列不';不存在,android,database,sqlite,Android,Database,Sqlite,好吧,我在这里被难住了。我收到一个错误,eclipse/android说我的应用程序正在崩溃,因为表中不存在列。问题是,我没有使用它引用的列id,我找不到它这样做的任何原因 在my DB create语句中: private static final String CREATE_HISTORY_TABLE= " create table if not exists " + HISTORY_TABLE + " (id integer primar

好吧,我在这里被难住了。我收到一个错误,eclipse/android说我的应用程序正在崩溃,因为表中不存在列。问题是,我没有使用它引用的列id,我找不到它这样做的任何原因

在my DB create语句中:

 private static final String CREATE_HISTORY_TABLE=
            " create table if not exists  " + HISTORY_TABLE +
            " (id integer primary key autoincrement," +
            " DebtName text, Date date, Payment real )";
在我的onCreate中:

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.paymenthistory_dialog);
  Bundle extras = getIntent().getExtras();
  String debtname = extras.getString(DbAdapter.KEY_DEBT);
  String[] from = new String[]{ DbAdapter.KEY_HISTORY_DATE, DbAdapter.KEY_HISTORY_PAYMENT};
  int[] to = new int[]{R.id.PAYMENTDATE, R.id.PAYMENTDATE};
  ListView paymenthistory = (ListView)findViewById(R.id.paymenthistorylist);
  DatabaseHelper db = new DatabaseHelper(this);
  Cursor PaymentsCursor = db.getReadableDatabase().rawQuery("SELECT * FROM tblPaymentHistory WHERE DebtName = '"+debtname+"'", null);
---> SimpleCursorAdapter HistoryAdapter = new SimpleCursorAdapter(PaymentHistory.this, R.layout.paymenthistoryrow, PaymentsCursor, from, to);
          paymenthistory.setAdapter(HistoryAdapter);
}   
带箭头的线就是有错误的线。我已经在sqlite浏览器中打开了DB,它的列名是“id”,但当我测试我的活动时,在eclipse中始终会出现以下错误:

11-18 00:26:40.775:E/AndroidRuntime(18419):原因:java.lang.IllegalArgumentException:列“\u id”不存在


这是因为以前在未添加id字段时创建了“表历史记录”\u table,所以\u id会自动添加,现在不会更改


解决方案是卸载应用程序并再次运行应用程序。现在,将使用定义的id字段创建表

将create语句中的'id'更改为'\u id',然后增加数据库版本。我认为它的工作很好

\u id
是SQLite中的一个特殊列。通常,如果不创建它,它会自动创建

发生此错误的原因是
SimpleCursorAdapter
需要一个名为
\u id
的列

要解决此问题,您可以

  • 更改查询,使其类似于:

    选择不同的id作为\u id

  • 或者重新创建表并将
    id
    重命名为
    \u id


事实上,据我所知,在安卓系统中创建数据库时,最好将主键命名为
\u id
。在这种情况下,安卓系统知道它是主键。因此,请尝试重命名它并再次运行代码。我认为它应该可以工作。谢谢你修复了它……我想你可以使用任何名称作为ID列,但更改为_id修复了它!