Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 显示列表视图时出现illegalstateexception_Android_Listview_Illegalstateexception - Fatal编程技术网

Android 显示列表视图时出现illegalstateexception

Android 显示列表视图时出现illegalstateexception,android,listview,illegalstateexception,Android,Listview,Illegalstateexception,我在listview中显示内容时出错。 错误显示: 05-03 08:00:13.575: E/AndroidRuntime(3341): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.lthomepage/com.android.lthomepage.ListViewDetails}: java.lang.IllegalArgumentExce

我在listview中显示内容时出错。 错误显示:

 05-03 08:00:13.575: E/AndroidRuntime(3341): java.lang.RuntimeException: Unable to start activity                    ComponentInfo{com.android.lthomepage/com.android.lthomepage.ListViewDetails}: java.lang.IllegalArgumentException:    column '_id' does not exist
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.os.Looper.loop(Looper.java:137)
05-03 08:00:13.575: E/AndroidRuntime(3341): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.support.v4.widget.CursorAdapter.init(CursorAdapter.java:174)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.support.v4.widget.CursorAdapter.<init>(CursorAdapter.java:151)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.support.v4.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:93)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at android.support.v4.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:89)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at com.android.lthomepage.ListViewDetails.displaylistView(ListViewDetails.java:77)
05-03 08:00:13.575: E/AndroidRuntime(3341):     at       com.android.lthomepage.ListViewDetails.onCreate(ListViewDetails.java:42)
数据库代码为:

public Cursor fetchDetails()
{

    createAllValuesTable();
    Cursor mCursor=db.query(AllValuesTable, new String[] {KEY_NAME,KEY_APPNO,KEY_AMOUNT}, null, null, null, null, null);

     if (mCursor != null) {
           mCursor.moveToFirst();
          }
          return mCursor;
}
有什么问题我好像弄不明白?? 我没有任何列作为id,我也没有从wer那里看到这个!
请帮忙!谢谢

来自Android开发者网站

将数据从游标公开到ListView小部件的适配器。光标必须包含一个名为“\u id”的列,否则将无法工作。

您正试图将光标与
SimpleCursorAdapter
一起使用,该光标需要一个名为
\u id
的列。只需编辑表创建语句并添加一个名为
\u id
的列即可。声明应如下:


\u id INTEGER主键自动递增

嘿,非常感谢!这真的很有帮助!问题终于解决了!
public Cursor fetchDetails()
{

    createAllValuesTable();
    Cursor mCursor=db.query(AllValuesTable, new String[] {KEY_NAME,KEY_APPNO,KEY_AMOUNT}, null, null, null, null, null);

     if (mCursor != null) {
           mCursor.moveToFirst();
          }
          return mCursor;
}