DatabaseAdapter.java と DBHelper.java の 2 つの Java クラスがあります。ユーザー ログイン用に記述されたコードが正しくありません。エラーの場所とコードの記述方法がわかりません。誰か助けてください。「new DBHelper(this)」は、プログラム内で下線が引かれています。
public class DatabaseAdapter {
// Table attributes
public static final String TABLE_USER = "user_table";
//User Table
public static final String USER_ID = "_id";
public static final String UNAME = "name";
public static final String USURNAME = "surname";
public static final String USERNAME = "username";
public static final String UPASSWORD = "password";
public static final String UEMAILADDRESS = "emailadd";
public boolean Login(String username, String password) throws SQLException
{
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor mCursor = db.rawQuery("SELECT * FROM " + TABLE_USER + " WHERE username=? AND password=?", new String[]{username,password});
if (mCursor != null) {
if(mCursor.getCount() > 0)
{
return true;
}
}
mCursor.close();
db.close();
return false;
}
ここでは、テーブルが作成される DBHelper で。
public class DBHelper extends SQLiteOpenHelper {
public static final int DB_VERSION = 1;
public static final String DB_NAME = "moneym.db";
public DBHelper(Context ctx) {
super(ctx, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
createTables(db);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
}
public void createTables(SQLiteDatabase database) {
String UserTable = "create table if not exists " + DatabaseAdapter.TABLE_USER + " ( " +
DatabaseAdapter.USER_ID + " integer primary key autoincrement, "
+ DatabaseAdapter.UNAME + " text, "
+ DatabaseAdapter.USURNAME + " text, "
+ DatabaseAdapter.USERNAME + " text, "
+ DatabaseAdapter.UPASSWORD + " text, "
+ DatabaseAdapter.UEMAILADDRESS + " text);";
try {
database.execSQL(UserTable);
Log.d("Users","Tables created!");
}
catch(Exception ex) {
Log.d("Users", "Error in DBHelper.onCreate() : " + ex.getMessage());
}
}