我不知道哪裏出了問題,但是當我點擊登錄時,這些值將不會顯示。這是我的profile.java無法在我的SQLite數據庫中顯示我的數據[Android]
TextView vName = (TextView) findViewById(R.id.tvName);
TextView vEmail = (TextView) findViewById(R.id.tvEmail);
TextView vMobile = (TextView) findViewById(R.id.tvMobile);
Contact contact = new Contact();
vName.setText(contact.getName().toString());
vEmail.setText(contact.getEmail().toString());
vMobile.setText(contact.getMobile().toString());
Button btnOut = (Button) findViewById(R.id.btnOut);
btnOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent Outent = new Intent(Profile.this,MainActivity.class);
startActivity(Outent);
finish();
}
});
這裏是我的數據庫代碼,我試圖使我DatabaseHelper.java的方法但它仍然沒有奏效。我想要像你們這樣的專業人士提供一些幫助。 DatabaseHelper.java
private static final String TABLE_CREATE = "create table contacts(id integer primary key not null ,"+
"name text not null, email text not null, pass text not null, mobile text not null);";
public DatabaseHelper(Context context){
super(context, DATABASE_NAME,null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
this.db =db;
}
public void insertContact(Contact c){
db = this.getWritableDatabase();
ContentValues values = new ContentValues();
String query = "select * from contacts";
Cursor cursor = db.rawQuery(query,null);
int count = cursor.getCount();
values.put(COLUMN_ID,count);
values.put(COLUMN_NAME,c.getName());
values.put(COLUMN_EMAIL,c.getEmail());
values.put(COLUMN_PASS, c.getPass());
values.put(COLUMN_MOBILE, c.getMobile());
db.insert(TABLE_NAME,null,values);
db.close();
}
public Cursor getAllData(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select email,name,mobile from"+TABLE_NAME,null);
return res;
}
public String searchPass(String email){
db = this.getReadableDatabase();
String query = "select email, pass from " + TABLE_NAME;
Cursor cursor = db.rawQuery(query,null);
String a, b;
b = "not found";
if(cursor.moveToFirst()){
do{
a = cursor.getString(0);
if(a.equals(email)){
b = cursor.getString(1);
break;
}
}while(cursor.moveToNext());
}
return b;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String query = "DROP TABLE IF EXISTS" + TABLE_NAME;
db.execSQL(query);
this.onCreate(db);
}
哪裏是數據庫的部分? – Fusselchen