i am trying to make an app which you can enter two comments into the database at once, it keeps crashing oncreate when it tries to add all the comments to the list. any help would be most appreciated. thank you in advance.
//on create method @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comments);
etComm = (EditText) findViewById(R.id.etComment);
etname = (EditText) findViewById(R.id.etName);
//Create a new data manager objects
datasource = new CommentsManageData(this);
datasource.open(); //Create or open the database
List<Comment> values = datasource.getAllComments();
// use the SimpleCursorAdapter to show elements in a ListView
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
android.R.layout.simple_list_item_1,values);
setListAdapter(adapter);
}
//This retrieves data from the database and puts it into an ArrayList
public List<Comment> getAllComments() {
List<Comment> comments = new ArrayList<Comment>();
//Retrieve all comments - returns a cursor positioned
//over first item in the results
Cursor cursor = database.query(CommentsSQLiteHelper.TABLE_COMMENTS,
allColumns, null, null, null, null, null);
cursor.moveToFirst(); //Just in case it wasn't there already
while (!cursor.isAfterLast()) {
Comment comment = cursorToComment(cursor);
comments.add(comment);//Add the comment
cursor.moveToNext(); // move to the next item in results
}
cursor.close(); // make sure to close the cursor
return comments;
}
04-28 04:10:35.998: E/SQLiteLog(1332): (1) no such column: name 04-28 04:10:36.068: E/AndroidRuntime(1332): FATAL EXCEPTION: main 04-28 04:10:36.068: E/AndroidRuntime(1332): Process: cct.mad.lab, PID: 1332 04-28 04:10:36.068: E/AndroidRuntime(1332): java.lang.RuntimeException: Unable to start activity ComponentInfo{http://ift.tt/1Jx8tD0}: android.database.sqlite.SQLiteException: no such column: name (code 1): , while compiling: SELECT _id, comment, name FROM comments 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.ActivityThread.access$800(ActivityThread.java:135) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.os.Handler.dispatchMessage(Handler.java:102) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.os.Looper.loop(Looper.java:136) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.ActivityThread.main(ActivityThread.java:5017) 04-28 04:10:36.068: E/AndroidRuntime(1332): at java.lang.reflect.Method.invokeNative(Native Method) 04-28 04:10:36.068: E/AndroidRuntime(1332): at java.lang.reflect.Method.invoke(Method.java:515) 04-28 04:10:36.068: E/AndroidRuntime(1332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 04-28 04:10:36.068: E/AndroidRuntime(1332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 04-28 04:10:36.068: E/AndroidRuntime(1332): at dalvik.system.NativeStart.main(Native Method) 04-28 04:10:36.068: E/AndroidRuntime(1332): Caused by: android.database.sqlite.SQLiteException: no such column: name (code 1): , while compiling: SELECT _id, comment, name FROM comments 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200) 04-28 04:10:36.068: E/AndroidRuntime(1332): at cct.mad.lab.CommentsManageData.getAllComments(CommentsManageData.java:33) 04-28 04:10:36.068: E/AndroidRuntime(1332): at cct.mad.lab.CommentsApp.onCreate(CommentsApp.java:22) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.Activity.performCreate(Activity.java:5231) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 04-28 04:10:36.068: E/AndroidRuntime(1332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
Aucun commentaire:
Enregistrer un commentaire