pofy_zhu 2015-05-08 06:54 采纳率: 62.5%
浏览 4089
已采纳

android数据库插入问题老是出错。新手。很急,在线等。谢谢大神了

public class MyDatabaseHelper extends SQLiteOpenHelper
{
final String CREATE_TABLE_SQL =
"create table dict(_id integer primary " +
"key autoincrement , word , detail)";
public MyDatabaseHelper(Context context, String name, int version)
{
super(context, name, null, version);
}
@Override
public void onCreate(SQLiteDatabase db)
{
// 第一次使用数据库时自动建表
db.execSQL(CREATE_TABLE_SQL);
}
@Override
public void onUpgrade(SQLiteDatabase db
, int oldVersion, int newVersion)
{
System.out.println("--------onUpdate Called--------"
+ oldVersion + "--->" + newVersion);
}
}

 public class Dict extends Activity{
    MyDatabaseHelper dbHelper;
    Button insert = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dbHelper = new MyDatabaseHelper(this , "myDict.db3",1);
        insert = (Button) findViewById(R.id.insert);

        insert.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String word = ((EditText)findViewById(R.id.word)).getText().toString();
                String detail = ((EditText)findViewById(R.id.detail)).getText().toString();
                insertData(dbHelper.getReadableDatabase(),"56465" ,"56165");


            }
        });
    }


    private void insertData(SQLiteDatabase db , String word , String detail){
        db.execSQL("insert into dict values(null,?,?)" , new String[] {word ,detail});
    }

}
  • 写回答

4条回答 默认 最新

  • danielinbiti 2015-05-08 06:59
    关注
     insertData(dbHelper.getWritableDatabase(),"56465" ,"56165");不是getReadableDatabase
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键