-2

enter image description here

I am creating notepad application and want to update my notes but I am unable to record in sqlite database. Please check my update query I am sharing error details.

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();

            }

            });
halfer
  • 19,824
  • 17
  • 99
  • 186
raman rayat
  • 404
  • 5
  • 15

2 Answers2

4

you have declared SQLiteDatabase mydb1 but not initialized it. Error is in this line.

mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});

You need to initialize mydb1.

Ravi
  • 34,851
  • 21
  • 122
  • 183
2

Looks like in

mydb1.execSQL("UPDATE notes SET (title,notetext) values(?,?);",new String[]{titleedit.getText().toString(),notetextedit.getText().toString()});

mydb1 is null,you didn't new and init mydb1.

starkshang
  • 8,228
  • 6
  • 41
  • 52