德莱華 2015-08-22 15:33 采纳率: 75%
浏览 3862
已采纳

android在数据库中查找相应的数据时出错。

Cursor cursor=myDatabase.rawQuery("select ids,title,times from goodtime" , null);
cursor.moveToFirst();
while(!cursor.isAfterLast()){
int id=cursor.getInt(cursor.getColumnIndex("ids"));
String title=cursor.getString(cursor.getColumnIndex("title"));
String times=cursor.getString(cursor.getColumnIndex("times"));
System.out.println(title);
System.out.println(cursor.getColumnIndex("bj"));
String beijing=cursor.getString(cursor.getColumnIndex("bj"));

    上面是我的代码,title还是可以正常查找的,但是bj这个变量的值确实-1,同时报出错误java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notebook/com.example.notebook.Notebook}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
    这是我创建的表:
    String ml="create table goodtime(ids integer PRIMARY KEY autoincrement,title text,content text,times text,ptpath text,mppath text,vdpath text,islock integer,password text,bj text)";
    arg0.execSQL(ml);
    网上说有可能大小写不对,我仔细查看了变量名都是一致的啊
    求各位大神帮我看一下,指点一下我,先谢谢了!
  • 写回答

4条回答

  • devmiao 2015-08-22 15:58
    关注

    看下你的数据库中有没有对应的记录

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示