0
我想插入一個短信到一個數據庫表。
但是當我調試程序,我看到這個錯誤No such table:sms.GroupTbl(code 1):,while compiling:INSERT INTO sms.GroupTbl(txt,tel)VALUES(?,?)
No such table: sms.GroupTbl (code 1): , while compiling: INSERT INTO sms.GroupTbl(txt,tel) VALUES (?,?)
我曾嘗試重新安裝應用程序,並在清單改變我的DB名稱,但既不這些解決方案的工作
DBAdapter.java
public class DBAdapter {
String[] AllColumnForStudents = {
KEY_ROWID,
KEY_NAME
};
String[] AllColumnForGroupSms = {
KEY_ROWID,
KEY_txt,
KEY_tel
};
static final String KEY_ROWID = "_id";
static final String KEY_NAME = "name";
static final String KEY_txt = "txt";
static final String KEY_tel = "tel";
static final String TAG = "DBAdapter";
//MyDBCategory
static final String DATABASE_NAME = "MyDB";
static final String DATABASE_MAINTABLE = "main.GroupTbl";
static final String DATABASE_Nametable = "sms.GroupTbl";
static final int DATABASE_VERSION =1;
private static final String CREATE_MAINTABLE = "CREATE TABLE "
+ DATABASE_MAINTABLE + "(" + KEY_ROWID + " INTEGER PRIMARY KEY autoincrement,"
+ KEY_NAME + " text not null)";
private static final String CREATE_Tsms = "CREATE TABLE "
+ DATABASE_Nametable + "(" + KEY_ROWID + " INTEGER PRIMARY KEY autoincrement,"
+ KEY_txt + " varchar(500) NOT NULL, " + KEY_tel + " varchar(30) NOT NULL) ";
private static final String SQL_DELETE_TABLES =
"DROP TABLE IF EXISTS " + DATABASE_MAINTABLE;
private static final String SQL_DELETE_Tsms =
"DROP TABLE IF EXISTS " + DATABASE_Nametable;
final Context context;
DatabaseHelper DBHelper;
SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(CREATE_MAINTABLE);
db.execSQL(CREATE_Tsms);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// if (newVersion < oldVersion) {
// Log.w("DBAdapter", "Updating database from version " + oldVersion + " to "
// + newVersion + " .Existing data will be lost.");
db.execSQL(SQL_DELETE_TABLES);
db.execSQL(SQL_DELETE_Tsms);
onCreate(db);
}
// }
}
public void onDelGroup()
{
// db = DBHelper.getWritableDatabase();
// db.ExecNonQuery("delete from "+ DATABASE_Nametable);
// db.delete(DATABASE_Nametable,null,null);
SQLiteDatabase db = DBHelper.getWritableDatabase();
db.execSQL("DELETE FROM sms.GroupTbl");
// db.close();
}
//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
**public long insertsms(String txt,String tel,String tabale)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_txt, txt);
initialValues.put(KEY_tel, tel);
long result= db.insert(tabale, null, initialValues);
return result;
}**
private List<ListAdapterSms> cursorToListsms(Cursor cursor) {
List<ListAdapterSms> sms = new ArrayList<ListAdapterSms>();
if (cursor.getCount() > 0)
{
while (cursor.moveToNext()) {
ListAdapterSms _sms = new ListAdapterSms();
_sms.setId(cursor.getString(0));
_sms.settxt(cursor.getString(1));
_sms.settel(cursor.getString(2));
sms.add(_sms);
} ;
}
return sms;
}
}
logcat的
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1589)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1461)
at www.project_category.ir.project_category.DBAdapter.insertsms(DBAdapter.java:132)
at www.project_category.ir.project_category.MSmsActivity.RetSms(MSmsActivity.java:132)
at www.project_category.ir.project_category.MSmsActivity.onCreate(MSmsActivity.java:90)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
at dalvik.system.NativeStart.main(Native Method)
12-21 13:38:55.997 26429-26429/www.project_category.ir.project_category E/SQLiteLog: (1) no such table: sms.GroupTbl
12-21 13:38:56.027 26429-26429/www.project_category.ir.project_category E/SQLiteDatabase: Error inserting txt=قسمت سوم عطسه!
آخرين اثر مهران مديري
عرضه انحصاري اينترنتي در ماي اپس
http://MyApps.ir
尼斯的答案。我想這是完美的 –