次の sqlite データベース コードでエラーが発生しました。誰かが私が間違っていることを修正できますか?? 以下は、問題にアクセスするための LOGCAT です。
別のメモとして、Google yahoo や hotmail ではなく、公式のメール ID でユーザーを登録してもらいたいのですが、フリーメールの使用を制限するにはどうすればよいですか??
DBヘルパー
public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "membersdb";
private static final String DATABASE_TABLE = "members"; // this is your
// table name
private static final String KEY_ROW_ID = "_id";
private static final String KEY_USERNAME = "username";
private static final String KEY_PASSWORD = "password";
private static final String KEY_FULLNAME = "fullname";
private static final String KEY_EMAILS = "emails";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE = "CREATE TABLE "
+ DATABASE_TABLE + " (" + KEY_ROW_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_USERNAME
+ " TEXT NOT NULL , " + KEY_EMAILS + " TEXT NOT NULL , "
+ KEY_PASSWORD + " TEXT NOT NULL , " + KEY_FULLNAME
+ " TEXT NOT NULL);";
public DBHelper(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 arg1, int arg2) {
db.execSQL("DROP TABLE IF EXISTS members");
onCreate(db);
}
}
DBアダプタ
public class DBAdapter {
private static final String DATABASE_TABLE = "members";
public static final String KEY_ROW_ID = "_id";
public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password";
public static final String KEY_FULLNAME = "fullname";
public static final String KEY_EMAILS = "emails";
SQLiteDatabase mDb;
Context mCtx;
DBHelper mDbHelper;
public DBAdapter(Context context) {
this.mCtx = context;
}
public DBAdapter open() throws SQLException {
mDbHelper = new DBHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
public long register(String username, String password, String fullnames, String emails) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_USERNAME, username);
initialValues.put(KEY_PASSWORD, password);
initialValues.put(KEY_FULLNAME, fullnames);
initialValues.put(KEY_EMAILS, emails);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
public boolean Login(String username, String password) throws SQLException {
Cursor mCursor = mDb.rawQuery("SELECT * FROM " + DATABASE_TABLE
+ " WHERE username=? AND password=?", new String[] { username,
password });
if (mCursor != null) {
if (mCursor.getCount() > 0) {
return true;
}
}
return false;
}
}
MemberRegister活動
public class MembersRegister extends Activity {
DBAdapter dbAdapter;
EditText txtUserName, fullname, authcodes, txtemail;
EditText txtPassword;
Button btnLogin;
Button btnRegister;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
authcodes = (EditText) findViewById(R.id.auth_code);
fullname = (EditText) findViewById(R.id.registerName);
txtUserName = (EditText) findViewById(R.id.userName);
txtPassword = (EditText) findViewById(R.id.registerPassword);
txtemail = (EditText) findViewById(R.id.registerEmail);
btnRegister = (Button) findViewById(R.id.btnRegister);
dbAdapter = new DBAdapter(this);
dbAdapter.open();
btnRegister.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtUserName.getWindowToken(), 0);
imm.hideSoftInputFromWindow(txtPassword.getWindowToken(), 0);
imm.hideSoftInputFromWindow(fullname.getWindowToken(), 0);
imm.hideSoftInputFromWindow(txtemail.getWindowToken(), 0);
try {
String username = txtUserName.getText().toString();
String password = txtPassword.getText().toString();
String fullnames = fullname.getText().toString();
String emails = txtemail.getText().toString();
long i = dbAdapter.register(username, password, fullnames,
emails);
if (i != -1)
Toast.makeText(MembersRegister.this,
"You have successfully registered",
Toast.LENGTH_LONG).show();
} catch (SQLException e) {
Toast.makeText(MembersRegister.this, "Some problem occurred",
Toast.LENGTH_LONG).show();
}
}
});
}
}
ログキャット
09-30 10:34:00.807: E/Database(368): Error inserting username=hello emails=hello password=hello fullname=hello
09-30 10:34:00.807: E/Database(368): android.database.sqlite.SQLiteException: table members has no column named emails: , while compiling: INSERT INTO members(username, emails, password, fullname) VALUES(?, ?, ?, ?);
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1149)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569)
09-30 10:34:00.807: E/Database(368): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
09-30 10:34:00.807: E/Database(368): at com.ideals.ideal.DBAdapter.register(DBAdapter.java:42)
09-30 10:34:00.807: E/Database(368): at com.ideals.ideal.MembersRegister$1.onClick(MembersRegister.java:50)
09-30 10:34:00.807: E/Database(368): at android.view.View.performClick(View.java:2485)
09-30 10:34:00.807: E/Database(368): at android.view.View$PerformClick.run(View.java:9080)
09-30 10:34:00.807: E/Database(368): at android.os.Handler.handleCallback(Handler.java:587)
09-30 10:34:00.807: E/Database(368): at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 10:34:00.807: E/Database(368): at android.os.Looper.loop(Looper.java:123)
09-30 10:34:00.807: E/Database(368): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-30 10:34:00.807: E/Database(368): at java.lang.reflect.Method.invokeNative(Native Method)
09-30 10:34:00.807: E/Database(368): at java.lang.reflect.Method.invoke(Method.java:507)
09-30 10:34:00.807: E/Database(368): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-30 10:34:00.807: E/Database(368): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-30 10:34:00.807: E/Database(368): at dalvik.system.NativeStart.main(Native Method)
前もって感謝します