Thursday, January 23, 2014

SimpleCursorAdapter related error


            
Younger beginner Andrews today to get a check from the database which is then returned to the cursor in association SimpleCursorAdapter, transferred from noon now, almost cried. Always being given, the great God who help out
trouble
 super.onCreate (savedInstanceState); 
DBHelper helper = new DBHelper (this);
/ / Query
Cursor c = helper.query ();
startManagingCursor (c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter (this, R.layout.result, c, new String [] {"_id", "SongsName"}, new int [] {R.id.ID, R.id.SongName}); < br />ListView listView = (ListView) findViewById (R.id.lv);
listView.setAdapter (adapter);
setContentView (R.layout.result);

What is the log information:
03-19 13:36:19.646: D / AndroidRuntime (4800): Shutting down VM
03-19 13:36:19.646: W / dalvikvm (4800): threadid = 3: thread exiting with uncaught exception (group = 0x4001b188)
03-19 13:36:19.646: E / AndroidRuntime (4800): Uncaught handler: thread main exiting due to uncaught exception
03-19 13:36:19.665: E / AndroidRuntime (4800): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.ly.music / com.ly.music.Query}: java.lang.IllegalArgumentException: column '_id' does not exist
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2496)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 2512)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.ActivityThread.access $ 2200 (ActivityThread.java: 119)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 1863)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.os.Handler.dispatchMessage (Handler.java: 99)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.os.Looper.loop (Looper.java: 123)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.ActivityThread.main (ActivityThread.java: 4363)
03-19 13:36:19.665: E / AndroidRuntime (4800): at java.lang.reflect.Method.invokeNative (Native Method)
03-19 13:36:19.665: E / AndroidRuntime (4800): at java.lang.reflect.Method.invoke (Method.java: 521)
03-19 13:36:19.665: E / AndroidRuntime (4800): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 860)
03-19 13:36:19.665: E / AndroidRuntime (4800): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 618)
03-19 13:36:19.665: E / AndroidRuntime (4800): at dalvik.system.NativeStart.main (Native Method)
03-19 13:36:19.665: E / AndroidRuntime (4800): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.database.AbstractCursor.getColumnIndexOrThrow (AbstractCursor.java: 314)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.widget.CursorAdapter.init (CursorAdapter.java: 111)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.widget.CursorAdapter . (CursorAdapter.java: 90)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.widget.ResourceCursorAdapter . (ResourceCursorAdapter.java: 47)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.widget.SimpleCursorAdapter . (SimpleCursorAdapter.java: 88)
03-19 13:36:19.665: E / AndroidRuntime (4800): at com.ly.music.Query.onCreate (Query.java: 22)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1047)
03-19 13:36:19.665: E / AndroidRuntime (4800): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2459)
03-19 13:36:19.665: E / AndroidRuntime (4800): ... 11 more
03-19 13:36:19.726: I / dalvikvm (4800): threadid = 7: reacting to signal 3
03-19 13:36:19.726: I / dalvikvm (4800): Wrote stack trace to '/ data / anr / traces.txt'


I always suggest _id does not exist, I see some people say in naming the primary key must be bound to the cursor sqlite query as "_id", when I built the table is _id, it obviously exists always say I do not exist, how back thing ah
Reply:
I have encountered this problem, browse a lot of sites that did not have a successful, really depressed, ask this question a lot of people ... http://stackoverflow.com/search?q=column+_id+does+ not + exist you look at this web site, send a message to find the answer!!!
Reply:
ListView listView = (ListView) findViewById (R.id.lv); listView.setAdapter (adapter); setContentView (R.layout.result);


Pro, you do not like this error? No Load layout to find ListView?
Reply:
new SimpleCursorAdapter (this, R.layout.result, c, new String [] {"_id", "SongsName"}, new int [] {R.id.ID, R.id.SongName});

Here is the item R.layout.result layout, you first change the complete look here other error bars
Reply:
The reason is that there is no _id field you must have a data source _id field, the cursor will return an error otherwise.
Reply:
Under change field names like, if using SQLite, you can use the SQL statement [field name] as _id alias instead
Reply:
reference to the second floor xiaanming reply:
ListView listView = (ListView) findViewById (R.id.lv); listView.setAdapter (adapter); setContentView (R . layout.result);


Pro, you do not like this error? No Load layout to find ListView?

Parents, are really prime Supreme ah. Hey this is not the item that can be seen in the layout file ah. I had changed over the
Reply:
references, 4th Floor billcools reply: there is no reason
_id field of your data source must have a _id field, otherwise the cursor will error.

Blessings, right right right, no later debugging found that indeed, but I built the table field names statement that "_id", later became "id", really strange, I do not know how to put my system field name changed
Reply:
cited a floor yunlong782 reply:
I have encountered this problem, browse a lot of sites that did not have a successful, really depressed, ask this question a lot of people ... http://stackoverflow.com/search?q=column+_id+does+not+exist you look at this web site, send a message to find the answer!!!

Brothers, I solve the problem you, you see me the following reply to my question are those caused. But there is little that the layout of the file containing the listView confused I started very fancy, top bar plus a lot of controls and some of the nested layout, and then put the listview below. It Grandma, which is not the result of listview display data, then angrily to delete a whole other controls, to put a listview, the problem is solved
Reply:
references, 5th Floor billcools reply: next
change field names like, if you are using SQLite, you can use the SQL statement [field name] as _id's alias instead
Brother, the best that specific point ah

No comments:

Post a Comment