Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

textview onlclicklistener

 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a simple application that creates notes (messages) and saves them in the sqlite database. This works fine.
But I am trying to add an edit and delete function. So when I click on the note which is listed with a listview I want 2 buttons to appear: delete and edit
if the edit button is clicked, then i can edit the textviews of the notes and save them. I tried adding the code for this.
And if the delete button is clicked it removes the note from the database.

Here is the code i tried for edit:


when i run the app and click on the note i get the message that The application has stopped unexpectedly
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the stack trace from the logcat output.
 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the log cat trace is very large but I found these errors about the database:
11-19 21:52:48.610: E/AndroidRuntime(14684): FATAL EXCEPTION: main
11-19 21:52:48.610: E/AndroidRuntime(14684): android.database.sqlite.SQLiteException: no such column: id: , while compiling: SELECT note_name, note_message FROM noteslist WHERE id=?
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1497)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1376)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1330)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1412)
11-19 21:52:48.610: E/AndroidRuntime(14684): at com.mad.noteslist.MainActivity$2.onItemClick(MainActivity.java:59)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.widget.ListView.performItemClick(ListView.java:3740)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2000)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.os.Handler.handleCallback(Handler.java:587)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.os.Handler.dispatchMessage(Handler.java:92)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.os.Looper.loop(Looper.java:130)
11-19 21:52:48.610: E/AndroidRuntime(14684): at android.app.ActivityThread.main(ActivityThread.java:3691)
11-19 21:52:48.610: E/AndroidRuntime(14684): at java.lang.reflect.Method.invokeNative(Native Method)
11-19 21:52:48.610: E/AndroidRuntime(14684): at java.lang.reflect.Method.invoke(Method.java:507)
11-19 21:52:48.610: E/AndroidRuntime(14684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
11-19 21:52:48.610: E/AndroidRuntime(14684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
11-19 21:52:48.610: E/AndroidRuntime(14684): at dalvik.system.NativeStart.main(Native Method)


I see it says there is no column called id but i do create it in another class file: String sql = "create table noteslist (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"note_name TEXT, note_message TEXT)";
It has no problem adding to the database
 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem. it was with the line Cursor c = mDb.query("noteslist", cols, "_id=?", vals, null, null, null);
the id was defined as _id but i was missing the _ symbol.

That has stopped the app crashing but nothing happens when i click the notes in the listview. I want to be able to edit them
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic