为什么我的记录更新给出空指针异常?
Why is my record update giving a null pointer exception?
我正在创建记事本应用程序并想更新我的笔记,但我无法在 sqlite 数据库中记录。请检查我的更新查询
我正在分享错误详细信息。
public class MainUpdateActivity extends Activity {
SQLiteDatabase mydb1;
EditText titleedit,notetextedit;
Button update;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
titleedit=(EditText)findViewById(R.id.title);
notetextedit=(EditText)findViewById(R.id.notetext);
update=(Button) findViewById(R.id.update);
Intent myintent = getIntent();
String product7 = myintent.getStringExtra("product1");
String product8 = myintent.getStringExtra("product");
titleedit.setText(product7);
notetextedit.setText(product8);
update.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});
Toast.makeText(getApplicationContext(), "note Updated", 3000).show();
Intent myIntent1 = new Intent(MainUpdateActivity.this,menu.class);
startActivity(myIntent1);
finish();
}
});
看起来像
mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});
mydb1
为 null,您没有新建和初始化 mydb1
。
您已声明 SQLiteDatabase mydb1
但未对其进行初始化。错误在这一行。
mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});
您需要初始化mydb1
。
我正在创建记事本应用程序并想更新我的笔记,但我无法在 sqlite 数据库中记录。请检查我的更新查询 我正在分享错误详细信息。
public class MainUpdateActivity extends Activity {
SQLiteDatabase mydb1;
EditText titleedit,notetextedit;
Button update;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
titleedit=(EditText)findViewById(R.id.title);
notetextedit=(EditText)findViewById(R.id.notetext);
update=(Button) findViewById(R.id.update);
Intent myintent = getIntent();
String product7 = myintent.getStringExtra("product1");
String product8 = myintent.getStringExtra("product");
titleedit.setText(product7);
notetextedit.setText(product8);
update.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});
Toast.makeText(getApplicationContext(), "note Updated", 3000).show();
Intent myIntent1 = new Intent(MainUpdateActivity.this,menu.class);
startActivity(myIntent1);
finish();
}
});
看起来像
mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});
mydb1
为 null,您没有新建和初始化 mydb1
。
您已声明 SQLiteDatabase mydb1
但未对其进行初始化。错误在这一行。
mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});
您需要初始化mydb1
。