我在谷歌搜索,在这里也在stackoverflow,我发现一些人的代码与我的相似.有人必须添加(onUpgrade方法)到他的代码,所以它将自动增加数据库版本….但我已经写了.我感到很困惑.请帮忙.. ??
这是数据库代码:
package group.com;import androID.content.ContentValues;import androID.content.Context;import androID.database.sqlException;import androID.database.sqlite.sqliteDatabase;import androID.database.sqlite.sqliteOpenHelper;import androID.util.Log;public class DBAdapter {public static final String KEY_admin_ROWID = "_ID";public static final String KEY_admin_fullname = "adminFullname";public static final String KEY_admin_Username = "adminUsername";public static final String KEY_admin_Password = "adminPassword";private static final String TAG = "DBAdapter";private static final String DATABASE_name = "RamiTariq";private static final String DATABASE_table = "info";private static final String DATABASE_table_admin = "admin";private static final int DATABASE_VERSION = 1;private static final String DATABASE_CREATE = "create table " + DATABASE_table + " (" + KEY_ROWID + " integer primary key autoincrement," + KEY_name + " text not null," + KEY_PSSWORD + " text not null," + KEY_F_name + " text not null," + KEY_DATE + " text not null," + KEY_JOB + " text not null," + KEY_ADDRESS + " text not null," + KEY_PHONE + " text not null," + KEY_NATIONAL_NUMBER + " text not null," + KEY_MONEY_SHOulD_PAY + " text null," + KEY_ACTUAL_MONEY + " text null);";private static final String DATABASE_CREATE_admin = "create table " + DATABASE_table_admin + " (" + KEY_admin_ROWID + " integer primary key autoincrement," + KEY_admin_fullname + " text not null," + KEY_admin_Username + " text not null," + KEY_admin_Password + " text not null);";private final Context context;private DatabaseHelper DBHelper;private 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); } public voID onCreate(sqliteDatabase db) { try { db.execsql(DATABASE_CREATE); db.execsql(DATABASE_CREATE_admin); } catch (sqlException e) { e.printstacktrace(); } } public voID onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) { Log.w(TAG,"Upgrading database from version " + oldVersion + " to " + newVersion + ",which will destroy all old data"); db.execsql("DROP table IF EXISTS "+DATABASE_table); db.execsql("DROP table IF EXISTS "+DATABASE_table_admin); onCreate(db); }}// ---opens the database---public DBAdapter open() throws sqlException { db = DBHelper.getWritableDatabase(); return this;}// ---closes the database---public voID close() { DBHelper.close();}//------insert an admin into the database-----public long insertadmin(String full_name,String user_name,String password ) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_admin_fullname,full_name); initialValues.put(KEY_admin_Username,user_name); initialValues.put(KEY_admin_Password,password); return db.insert(DATABASE_table_admin,initialValues);} }
这是活动代码:
package group.com; import androID.app.Activity; import androID.content.Intent; import androID.os.Bundle; import androID.vIEw.VIEw; import androID.vIEw.VIEw.OnClickListener; import androID.Widget.button; import androID.Widget.EditText; import androID.Widget.Toast;public class Insertadmin extends Activity {DBAdapter db = new DBAdapter(this);EditText fullname,username,password,rePassword;button insertadmin;public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.insertadmin); fullname = (EditText) findVIEwByID(R.ID.fullname); username = (EditText) findVIEwByID(R.ID.username); password = (EditText) findVIEwByID(R.ID.password); rePassword = (EditText) findVIEwByID(R.ID.rePassword); insertadmin = (button) findVIEwByID(R.ID.insertadmin); insertadmin.setonClickListener(new OnClickListener() { public voID onClick(VIEw arg0) { String fname = fullname.getText().toString(); String uname = username.getText().toString(); String pass = password.getText().toString(); String rePass = rePassword.getText().toString(); if(fname.length()==0 || uname.length()==0 || pass.length()==0 || rePass.length()==0) { displayMessage("Please Enter Full Data"); return; } if (uname.length() == 0) { displayMessage("Enter username"); return; } if (pass.length() == 0) { displayMessage("Enter The password"); return; } if(pass.equals(rePass)) { db.open(); long ID = db.insertadmin(fname,uname,pass); if(ID>0) { displayMessage(ID + "\nSuccessfuly Inserted"); } else { displayMessage("Not Inserted"); } db.close(); startActivity(new Intent(getBaseContext(),admin.class)) ; } else displayMessage("Your Passwords doesn't match"); } });}public voID displayMessage(String msg){ Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();} }解决方法 卸载您的应用程序,以便删除旧版本的数据库.
您的数据库版本仍为1,因此不运行onUpgrade().数据库文件已存在,因此onCreate()不会运行.现有的数据库文件不包含您在当前版本的onCreate()中创建的所有表.
总结以上是内存溢出为你收集整理的android.database.sqlite.SQLITeException:没有这样的表:编译时管理员:INSERT INTO …等全部内容,希望文章能够帮你解决android.database.sqlite.SQLITeException:没有这样的表:编译时管理员:INSERT INTO …等所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)