德莱華 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 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题