登録用のユーザー情報を受け入れるアプリを作成していますが、「そのようなテーブルはありません:UserAccount」というエラーが表示されました。以下は私のコードです。
私のDBHelper
public class DBAdapter
{
public static final String KEY_ROWID = "_id";
public static final String KEY_TITLE = "title";
public static final String KEY_FULLNAME = "fullname";
public static final String KEY_EMAIL = "email";
public static final String KEY_PASS = "password";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "pioneer.db";
private static final int DATABASE_VERSION = 1;
public static final String DATABASE_TABLE_NAME = "UserAccount";
private static final String DATABASE_CREATE =
"create table IF NOT EXISTS users (_id integer primary key autoincrement, "
+ "title text, fullname text, email text, password text);";
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);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
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 users");
onCreate(db);
}
}
//---opens the database---
public DBAdapter opendb() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
//---insert a title into the database---
public long insertUser(String title, String fullname,String email, String Password)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_FULLNAME, fullname);
initialValues.put(KEY_EMAIL, email);
initialValues.put(KEY_PASS, Password);
return db.insert(DATABASE_TABLE_NAME, null, initialValues);
}
//---deletes a particular title---
public boolean deleteTitle(long rowId)
{
return db.delete(DATABASE_TABLE_NAME, KEY_ROWID +
"=" + rowId, null) > 0;
}
//---retrieves all the titles---
public Cursor getAllUsers()
{
return db.query(DATABASE_TABLE_NAME, new String[] {
KEY_ROWID,
KEY_TITLE,
KEY_FULLNAME,
KEY_EMAIL,
KEY_PASS,
},
null,
null,
null,
null,
null);
}
//---retrieves a particular user---
public Cursor getUser(long rowId) throws SQLException
{
Cursor mCursor =
db.query(DATABASE_TABLE_NAME, new String[] {
KEY_ROWID,
KEY_TITLE,
KEY_FULLNAME,
KEY_EMAIL,
KEY_PASS,
},
KEY_ROWID + "=" + rowId,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
//---updates a title---
public boolean updateTitle(long rowId, String title, String fullname,String email, String Password)
{
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
args.put(KEY_FULLNAME, fullname);
args.put(KEY_EMAIL, email);
args.put(KEY_PASS, Password);
return db.update(DATABASE_TABLE_NAME, args,
KEY_ROWID + "=" + rowId, null) > 0;
}
}
そして、これは私がそれを使用する場所です
public class RegisterActivity extends Activity {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
final EditText full_Name = (EditText)findViewById(R.id.reg_fullname);
final EditText mMail = (EditText)findViewById(R.id.reg_email);
final EditText mPass = (EditText)findViewById(R.id.reg_password);
final TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
btn = (Button)findViewById(R.id.btnRegister);
final DBAdapter db = new DBAdapter(this);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (db !=null){
db.opendb();
long uid =db.insertUser("Mr", full_Name.getText().toString(), mMail.getText().toString(), mPass.getText().toString());
Cursor c = db.getUser(uid);
if (c !=null){
ShowMessage(c.getString(2));
}
}
db.close();
}
});
}
private void ShowMessage(String message){
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
// Listening to Login Screen link
/* loginScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Closing registration screen
// Switching to Login Screen/closing register screen
finish();
}
});*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_register, menu);
return true;
}
}
どんな助けでもありがたいです。