こんにちは、クエリに問題があります。私は何かが足りないと思いますが、何がわからないので、あなたの助けが必要です
java.lang.NullPointerException を返します
import android.annotation.TargetApi;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;
import android.util.Log;
@TargetApi(16)
public class logged extends Activity{
public TextView msg;
private SQLiteDatabase myDB = null;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.logged);
msg = (TextView) findViewById(R.id.msg);
myDB.openDatabase("data/data/com.example.login2/databases/aeglea", null, SQLiteDatabase.OPEN_READONLY);
try{
//here is the problem. Both kind of queries return the same error
//Cursor cur = myDB.query("user_login", new String[] {"username"}, null, null, null, null, null);
Cursor cur = myDB.rawQuery("SELECT username FROM user_login", null);
msg.setText("Hello");
}catch (Exception e1){
Log.e("DATABAZA","hola "+e1);
msg.setText("No Hello you creep");
}
}
}
そして、私のデータベースOnCreateは
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_NAME + "("
+ KEY_UID + " INTEGER PRIMARY KEY,"
+ KEY_NAME + " TEXT,"
+ KEY_LAST + " TEXT,"
+ KEY_EMAIL + " TEXT UNIQUE,"
+ KEY_USERNAME + " TEXT UNIQUE" + ")";
db.execSQL(CREATE_LOGIN_TABLE);
}
前もって感謝します