从SQLite数据库获取光标 [英] obtaining cursor from sqlite database

查看:237
本文介绍了从SQLite数据库获取光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照有关访问Android上的SQLite数据库教程,到目前为止,我已经做到了。

我的code到达栏目[]创建,然后我得到一个空指针异常...

我相信我的数据库是人口稠密,但我没有真正告诉方式。有人可以告诉我怎么检查? /得到这个工作?

 公共光标getAnimalCursor(){
    的System.out.println(在getAnimalCursor());
    的String [] =列新的String [] {_id,名};
    的System.out.println(栏目[]创建);
    光标C = myDataBase.query(动物,NULL,NULL,NULL,NULL,NULL,NULL);
    的System.out.println(光标创建);
    返回℃;
}


解决方案

检查您是否初始化MYDATABASE。这是空指针异常的原因。

I've tried to follow a tutorial on accessing sqlite databases on android and i've made it so far.

my code gets to "columns[] created" and then i get a null pointer exception...

I believe my database is populated but i have no way of really telling. can someone show me how to check? / get this working?

public Cursor getAnimalCursor() {
    System.out.println("in getAnimalCursor()");
    String[] columns = new String[] {"_id", "name"};
    System.out.println("columns[] created");
    Cursor c = myDataBase.query("animals", null,  null, null, null, null, null);
    System.out.println("cursor created");
    return c;
}

解决方案

Check if you have initialized myDataBase. It is the cause of null pointer exception.

这篇关于从SQLite数据库获取光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆