我有一個插入條目邏輯到我的android應用程序,它是完全響應,直到我上次訪問應用程序。 但它突然開始停止響應和運行。所以,請幫助我在我的邏輯中犯了什麼錯誤或錯誤,或者在我的編碼中突然響應sqlite以這種方式行事的問題。 請儘快幫助我,因爲我今天有最終的android應用程序演示文稿,而且我很少花時間省略。突然Android應用程序開始停止共鳴
在此先感謝您的幫助。
問候:)
繼我創建表的邏輯:
private static final int DATABASE_VERSION = 1; // db version
private static final String DATABASE_NAME = "db_Blood_Donation"; // db name
private static final String TABLE_NAME = "Table1"; // table name
// table fields
private static final String KEY_ID = "bid";
private static final String KEY_NAME = "bname";
private static final String KEY_DATE = "bdate";
private static final String KEY_GRP = "bgroup";
private static final String KEY_ADD = "baddress";
private static final String KEY_PH = "bphno";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
/* ------------- CREATE TABLE ------------- */
String CREATE_TABLE1 = "CREATE TABLE " + TABLE_NAME + "(" + KEY_ID
+ "INTEGER PRIMARY KEY, " + KEY_NAME + "TEXT, " + KEY_DATE
+ "TEXT, " + KEY_GRP + "TEXT, " + KEY_ADD + "TEXT, " + KEY_PH
+ "TEXT " + ")";
db.execSQL(CREATE_TABLE1);
Log.d("Table_Created", "table1");
}
以下是我的AddEntry邏輯:
/* ----------------- ADD USER ------------- */
void addUser(BDFieldClass user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, user.getBname());
cv.put(KEY_DATE, user.getBdate());
cv.put(KEY_GRP, user.getBgroup());
cv.put(KEY_ADD, user.getBaddress());
cv.put(KEY_PH, user.getPhno());
// INSERT ROWS
db.insertOrThrow(TABLE_NAME, null, cv);
db.close();
}
下面是我打電話是我的插入邏輯的代碼:
/* ------------------------------- ADD RECORED ----------- ------- -------------- */
btnadd.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
EditText ednm = (EditText)findViewById(R.id.txtname);
String name = ednm.getText().toString();
eddate = (EditText)findViewById(R.id.txtdate);
String date1 = eddate.getText().toString();
EditText edadd = (EditText)findViewById(R.id.txtadd);
String add = edadd.getText().toString();
EditText edno = (EditText)findViewById(R.id.txtno);
String phno = edno.getText().toString();
dbh.addUser(new BDFieldClass(name,date1,bgrp,add,phno));
以下是logcat的錯誤:
09-01 06:20:59.087: W/KeyCharacterMap(359): No keyboard for id 0
09-01 06:20:59.097: W/KeyCharacterMap(359): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-01 06:21:16.307: D/dalvikvm(359): GC_FOR_MALLOC freed 4630 objects/232480 bytes in 119ms
09-01 06:21:30.917: D/Table_Created(359): table1
09-01 06:21:30.936: I/Database(359): sqlite returned: error code = 1, msg = table Table1 has no column named bname
09-01 06:21:30.947: D/AndroidRuntime(359): Shutting down VM
09-01 06:21:30.947: W/dalvikvm(359): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-01 06:21:30.976: E/AndroidRuntime(359): FATAL EXCEPTION: main
09-01 06:21:30.976: E/AndroidRuntime(359): android.database.sqlite.SQLiteException: table Table1 has no column named bname: , while compiling: INSERT INTO Table1(bname, bphno, bgroup, bdate, baddress) VALUES(?, ?, ?, ?, ?);
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1432)
09-01 06:21:30.976: E/AndroidRuntime(359): at com.example.blooddonationapp.DBHelper.addUser(DBHelper.java:66)
09-01 06:21:30.976: E/AndroidRuntime(359): at com.example.blooddonationapp.CreateClass$2.onClick(CreateClass.java:80)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.view.View.performClick(View.java:2408)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.view.View$PerformClick.run(View.java:8816)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.os.Handler.handleCallback(Handler.java:587)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.os.Looper.loop(Looper.java:123)
09-01 06:21:30.976: E/AndroidRuntime(359): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-01 06:21:30.976: E/AndroidRuntime(359): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 06:21:30.976: E/AndroidRuntime(359): at java.lang.reflect.Method.invoke(Method.java:521)
09-01 06:21:30.976: E/AndroidRuntime(359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-01 06:21:30.976: E/AndroidRuntime(359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-01 06:21:30.976: E/AndroidRuntime(359): at dalvik.system.NativeStart.main(Native Method)
09-01 06:21:33.286: I/Process(359): Sending signal. PID: 359 SIG: 9
您應該發佈堆棧跟蹤。它比代碼更重要。 – wtsang02
@ wtsang02我發佈了LogCat狀態報告,請查看它。 – Rushabh