看板 java 關於我們 聯絡資訊
關於程式碼...我找一天還不知道原因,執行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); } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.136.153.183 ※ 文章網址: http://www.ptt.cc/bbs/java/M.1409991717.A.77D.html
gn00618777: 我看了logcat他說 no such titles table..... 09/06 16:33
gn00618777: 可我在 MyDBHelper 類別的 onCreate已經建立 titles 09/06 16:34
gn00618777: 資料表了 09/06 16:34
db.execSQL("CREATE TABLE titles (_id integer primary key autoincrement, " + "title text no null, price real no null)"); ※ 編輯: gn00618777 (220.136.153.183), 09/06/2014 16:35:42
qweqweqweqwe: 如果再MyDBHelper constructor 建立呢? 09/07 18:44
qweqweqweqwe: create table if not exist xxxx 09/07 18:45