我有一个名为“master”的表,其中包含 id、name、surname、gender 和指定
当我启动查询以获取 Cursor 时CursorAdapter 的对象我得到:
IllegalArgumentException: column '_id' does not exist when call to CursorAdaptor
但我没有名为“_id”的列。
谁能告诉我为什么会出现此错误?
这是堆栈跟踪:
07-13 15:45:40.582: WARN/System.err(295): java.lang.IllegalArgumentException: column '_id' does not exist
07-13 15:45:40.592: WARN/System.err(295): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
07-13 15:45:40.592: WARN/System.err(295): at android.widget.CursorAdapter.changeCursor(CursorAdapter.java:257)
07-13 15:45:40.602: WARN/System.err(295): at com.praumtech.names4baby.ui.NamesListAdapter.setCursor(NamesListAdapter.java:63)
07-13 15:45:40.602: WARN/System.err(295): at com.praumtech.names4baby.ui.BoysNamesListActivity.initNameList(BoysNamesListActivity.java:79)
07-13 15:45:40.602: WARN/System.err(295): at com.praumtech.names4baby.ui.BoysNamesListActivity.onCreate(BoysNamesListActivity.java:49)
07-13 15:45:40.602: WARN/System.err(295): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
07-13 15:45:40.602: WARN/System.err(295): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
07-13 15:45:40.612: WARN/System.err(295): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
07-13 15:45:40.612: WARN/System.err(295): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
07-13 15:45:40.612: WARN/System.err(295): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
07-13 15:45:40.612: WARN/System.err(295): at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 15:45:40.621: WARN/System.err(295): at android.os.Looper.loop(Looper.java:123)
07-13 15:45:40.621: WARN/System.err(295): at android.app.ActivityThread.main(ActivityThread.java:4203)
07-13 15:45:40.621: WARN/System.err(295): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 15:45:40.621: WARN/System.err(295): at java.lang.reflect.Method.invoke(Method.java:521)
07-13 15:45:40.621: WARN/System.err(295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-13 15:45:40.621: WARN/System.err(295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
07-13 15:45:40.631: WARN/System.err(295): at dalvik.system.NativeStart.main(Native Method)
最佳答案
发生这种情况是因为 CursorAdapter 在其使用的表中必须有一个 _id 列。
对于Android应用程序中的数据库(SQLite),最好在所有表中添加一个名为“_id”的列,以便能够使用CursorAdapter。
或者,你可以写一个sql语句,比如
select member_id as _id from member _table where ....."
为了获得一个 Cursor,它可以与 CursorAdapter 一起使用。
这是在 CursorAdaptor 的 documentation 中指定的:
Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work."
关于android - 非法参数异常 : column '_id' does not exist when call to SimpleCursorAdaptor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3236203/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2