final SQLiteDatabase userDB = this.openOrCreateDatabase("Users",MODE_PRIVATE,null);
final String fullNameText = fullName.getText().toString();
final String stateText = state.getText().toString();
final String zipcodeText = zipcode.getText().toString();
saveUserInfo.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
userDB.execSQL("CREATE TABLE IF NOT EXISTS allUsers (name VARCHAR, zipcode VARCHAR, state VARCHAR, id INTEGER PRIMARY KEY)");
userDB.execSQL("INSERT INTO allUsers(name, zipcode, state) VALUES (" + fullNameText + ", " + zipcodeText + ", " + stateText + ")");
Cursor c = userDB.rawQuery("SELECT * FROM allUsers", null);
int nameIndex = c.getColumnIndex("name");
int zipcodeIndex = c.getColumnIndex("zipcode");
int stateIndex = c.getColumnIndex("state");
int idIndex = c.getColumnIndex("id");
c.moveToFirst();
while (c != null) {
Log.i("Name-", c.getString(nameIndex));
Log.i("Zipcode-", c.getString(zipcodeIndex));
Log.i("State-", c.getString(stateIndex));
Log.i("id", Integer.toString(c.getInt(idIndex)));
c.moveToNext();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
エラーここではログ
>06-20 17:21:38.498 5433-5433/com.haasith.creation.jantan W/System.err: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: INSERT INTO allUsers(name, zipcode, state) VALUES (, ,)
>06-20 17:21:38.498 5433-5433/com.haasith.creation.jantan W/System.err: #################################################################
>06-20 17:21:38.498 5433-5433/com.haasith.creation.jantan W/System.err: Error Code : 1 (SQLITE_ERROR)
>06-20 17:21:38.498 5433-5433/com.haasith.creation.jantan W/System.err: Caused By : SQL(query) error or missing database.
>06-20 17:21:38.498 5433-5433/com.haasith.creation.jantan W/System.err: (near ",": syntax error (code 1): , while compiling: INSERT INTO allUsers(name, zipcode, state) VALUES (, ,))
>06-20 17:21:38.498 5433-5433/com.haasith.creation.jantan W/System.err: #################################################################
文字列はプリミティブ型ではなく、参照型です。あなたの答えは正しいです(彼は 'OnClickListener'の中で文字列を取得する必要があります)。 – Karakuri
@ Karakuri、あなたは正しい、私は遠く最後になります。 – chengpohi
logcatは最終的な文字列がカラム名であると考える> 06-21 00:42:46.090 17205-17205/com.haasith.creation.jantan E/SQLiteLog:(jkjjk > 06-21 00:42: (名前、郵便番号、州)をコンパイル中に:INSERT INTO allUsers(名前、郵便番号、州):46.090 17205-17205/com.haasith.creation.jantan W/System.err:android.database.sqlite.SQLiteException:いいえそのような列:jkjjk VALUES(jkjjk、989889、jjknj)@karakuri –