-1
テーブルを作って情報を入れるだけです。いくつかのコードを作成しますが、それは私にエラーなぜフィールドは作成されませんか?
E/SQLiteLog: (1) table tableOne has no column named email
E/SQLiteDatabase: Error inserting email=Email1 name=Name1
android.database.sqlite.SQLiteException: table tableOne has no column named email (code 1): , while compiling: INSERT INTO tableOne(email,name) VALUES (?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
を与え、私のコードは、アプリケーションをアンインストールし、エミュレータにインストールし直すと問題が存在してチェックすること
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
final String LOG_TAG = "myLogs";
Button btnAdd;
Button btnRead;
EditText editNameField;
EditText editEmailField;
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAdd = (Button) findViewById(R.id.btn_add);
btnRead = (Button) findViewById(R.id.btn_read);
editNameField = (EditText) findViewById(R.id.edit_name);
editEmailField = (EditText) findViewById(R.id.edit_email);
dbHelper = new DBHelper(this);
btnAdd.setOnClickListener(this);
btnRead.setOnClickListener(this);
}
@Override
public void onClick(View view) {
ContentValues cv = new ContentValues();
String name = editNameField.getText().toString();
String email = editEmailField.getText().toString();
SQLiteDatabase db = dbHelper.getWritableDatabase();
switch (view.getId()){
case R.id.btn_add:
Log.d(LOG_TAG, "--- Insert in mytable: ---");
cv.put("name", name);
cv.put("email", email);
long rowID = db.insert("tableOne", null, cv);
Log.d(LOG_TAG, "row inserted, ID = " + rowID);
break;
case R.id.btn_read:
Log.d(LOG_TAG, "--- Rows in mytable: ---");
Cursor c = db.query("tableOne",
null,
null,
null,
null,
null,
null
);
if (c.moveToFirst()){
int idColIndex = c.getColumnIndex("id");
int nameColIndex = c.getColumnIndex("name");
int emailColIndex = c.getColumnIndex("email");
do {
Log.d(LOG_TAG,
"ID = " + c.getInt(idColIndex) +
", name = " + c.getString(nameColIndex) +
", email = " + c.getString(emailColIndex));
} while (c.moveToNext());
} else {
Log.d(LOG_TAG, "0 rows");
c.close();
break;
}
}
}
class DBHelper extends SQLiteOpenHelper{
public DBHelper(Context context) {
super(context, "tableOne", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(LOG_TAG, "--- onCreate database ---");
db.execSQL("create table tableOne ("
+ "id integer primary key autoincrement,"
+ "name text,"
+ "email text" + ");");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
}
アプリケーションをアンインストールします。もう一度一度チェックしてください。 –