Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更新SQLite数据库中的数据_Java_Android_Android Sqlite - Fatal编程技术网

Java 更新SQLite数据库中的数据

Java 更新SQLite数据库中的数据,java,android,android-sqlite,Java,Android,Android Sqlite,我知道这个问题在这个网站上被问了很多次,问的方式多种多样,但没有一个对我有效。 我需要从活动中将数据更新到我的数据库。 我使用了以下代码: public class EditAccount extends Activity { private SQLiteDatabase database; private MySQLiteHelper dbHelper; ...... } public void update_acc(View view){ EditText accN

我知道这个问题在这个网站上被问了很多次,问的方式多种多样,但没有一个对我有效。 我需要从活动中将数据更新到我的数据库。 我使用了以下代码:

public class EditAccount extends Activity {

private SQLiteDatabase database;
    private MySQLiteHelper dbHelper;
......
}
public void update_acc(View view){
        EditText accName=(EditText)findViewById(R.id.acc_name);
        EditText comment=(EditText)findViewById(R.id.comments);
        String acc_name=accName.getText().toString();
        String comments=comment.getText().toString();
        Intent intent=getIntent();
        int id =(int) intent.getExtras().getLong("data_id"); 
        String data_id= Integer.valueOf(id).toString();

        //When i debug the app it comes here and stops:
        database = dbHelper.getWritableDatabase();
        database.execSQL("Update comments set acc_name='"+acc_name+"', 
    comment='"+comments+"' where id="+id, null);
        database.close();
        Toast.makeText(getBaseContext(), "Account updated; Acc Name:"+acc_name+" Comment:"+comments, Toast.LENGTH_LONG).show();
        super.onBackPressed();}
请看一下,看看有没有什么问题。 请帮忙

提前感谢,, 等待您的答复…

它是这样做的:

        EditText accName=(EditText)findViewById(R.id.acc_name);
        EditText comment=(EditText)findViewById(R.id.comments);
        String acc_name=accName.getText().toString();
        String comments=comment.getText().toString();
        Intent intent=getIntent();
        int id =(int) intent.getExtras().getLong("data_id"); 
        String data_id= Integer.valueOf(id).toString();

        database = dbHelper.getWritableDatabase();
          String query="Update comments set acc_name='"+acc_name+"', comment='"+comment+"' where _id="+id;
          database.execSQL(query);

        //Leave a message and go back
        Toast.makeText(getBaseContext(), "Account updated; Acc_name:"+acc_name+", Comment:"+comments, Toast.LENGTH_LONG).show();
        super.onBackPressed();

请说明您看到的错误是什么或为什么它不起作用,如果logcat中有错误,请发布它您是否正在初始化dbHelper?如何从logcat中获取错误?您是否使用Eclipse?不要紧..我得到了解决方案