[問題]Android 的 database 問題

作者: gn00618777 (非常念舊)   2014-09-06 16:21:52
關於程式碼...我找一天還不知道原因,執行APP時,出現問題
點擊新增紀錄 button 時,它回傳 -1...也就是沒新增成功 = ="
請問程式碼是哪裡可能出錯呢? 謝謝。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//建立SQLiteOpenHelper物件
dbHelper=new MyDBHelper(this);
db=dbHelper.getWritableDatabase();
//取得TextView物件
output=(TextView)findViewById(R.id.lblOutput);
txtTitle=(EditText)findViewById(R.id.txtTitle);
txtPrice=(EditText)findViewById(R.id.txtPrice);
txtNewPrice=(EditText)findViewById(R.id.txtNewPrice);
}
public void btn1_Click(View view){
long id;
ContentValues cv=new ContentValues();
cv.put("title", txtTitle.getText().toString());;
double price=Double.parseDouble(txtPrice.getText().toString());
cv.put("price", price);;
id=db.insert(DATABASE_TABLE, null, cv);
output.setText("新增記錄成功: "+id);
}
作者: gn00618777 (非常念舊)   2014-09-06 16:33:00
我看了logcat他說 no such titles table.....可我在 MyDBHelper 類別的 onCreate已經建立 titles資料表了
作者: qweqweqweqwe (4qwe)   2014-09-07 18:44:00
如果再MyDBHelper constructor 建立呢?create table if not exist xxxx

Links booklink

Contact Us: admin [ a t ] ucptt.com