嘿,现在我可以将数据保存在我的数据库中,但它不会显示在数据库活动本身中。
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); onCreateDBAndDBTabled(); //DB und Tables erstellen wenn noch nicht vorhanden setContentView(R.layout.main); }
private void onCreateDBAndDBTabled() {
myDB = this.openOrCreateDatabase(MY_DB_NAME, Context.MODE_PRIVATE, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
+ " ( id integer primary key autoincrement,"+
"Name varchar(100),"+
"Comment varchar(128),"+
"BookingDetails varchar(255),"+
"CustomerProject integer(3),"+
"editable varchar(15))"
+";");
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_PROJECTS, 0, R.string.menuProjects)
.setShortcut('1', 'f')
.setIcon(R.drawable.icon);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case MENU_PROJECTS:
Intent iProjects = new Intent(this, Projects.class);
startActivity(iProjects);
return true;
}
return false;
}
}
这是插入语句
{
ContentValues cv = new ContentValues();
cv.put ( "Name", Name.getText().toString() );
cv.put ( "Comment", Comment.getText().toString() );
cv.put ( "BookingDetails", BookingDetails.getText().toString() );
cv.put ( "Project_kind", i );
cv.put ( "Editable", Editable.getText().toString() );
myDB.insert ( Projectshome.MY_DB_TABLE , null, cv);
}
finish();
return true;
this is my manifest:
</manifest>
这是我点击保存按钮时的 LogCat 输出:
02-09 11:41:53.850: ERROR/Database(719): Error inserting BookingDetails=BookingDetails Project_kind=0 Name=Name Editable=Editable Comment=Comment
02-09 11:41:53.850: ERROR/Database(719): android.database.sqlite.SQLiteException: table projects has no column named Project_kind: , while compiling: INSERT INTO projects(BookingDetails, Project_kind, Name, Editable, Comment) VALUES(?, ?, ?, ?, ?);
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:925)
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1300)
02-09 11:41:53.850: ERROR/Database(719): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1173)
02-09 11:41:53.850: ERROR/Database(719): at versuch.datenbank.Projects_New.onOptionsItemSelected(Projects_New.java:132)
02-09 11:41:53.850: ERROR/Database(719): at android.app.Activity.onMenuItemSelected(Activity.java:2085)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:820)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:813)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:519)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
02-09 11:41:53.850: ERROR/Database(719): at android.view.View.onTouchEvent(View.java:3828)
02-09 11:41:53.850: ERROR/Database(719): at android.widget.TextView.onTouchEvent(TextView.java:6291)
02-09 11:41:53.850: ERROR/Database(719): at android.view.View.dispatchTouchEvent(View.java:3368)
02-09 11:41:53.850: ERROR/Database(719): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
02-09 11:41:53.850: ERROR/Database(719): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1691)
02-09 11:41:53.850: ERROR/Database(719): at android.view.ViewRoot.handleMessage(ViewRoot.java:1525)
02-09 11:41:53.850: ERROR/Database(719): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 11:41:53.850: ERROR/Database(719): at android.os.Looper.loop(Looper.java:123)
02-09 11:41:53.850: ERROR/Database(719): at android.app.ActivityThread.main(ActivityThread.java:3948)
02-09 11:41:53.850: ERROR/Database(719): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 11:41:53.850: ERROR/Database(719): at java.lang.reflect.Method.invoke(Method.java:521)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
02-09 11:41:53.850: ERROR/Database(719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
02-09 11:41:53.850: ERROR/Database(719): at dalvik.system.NativeStart.main(Native Method)
希望你能再次帮助我:)