private void saveChangeRus() { String word = txtWord.getText().toString().trim(); String translation = txtMultiLine.getText().toString().trim(); int type = 1; ContentValues values = new ContentValues(); values.put(DictionaryContract.DictionaryEntry.COLUMN_WORD, word); values.put(DictionaryContract.DictionaryEntry.COLUMN_TRANSLATION, translation); values.put(DictionaryContract.DictionaryEntry.COLUMN_TYPE, type); // ВставляСм Π½ΠΎΠ²Ρ‹ΠΉ ряд Π² Π±Π°Π·Ρƒ Π΄Π°Π½Π½Ρ‹Ρ… ΠΈ Π·Π°ΠΏΠΎΠΌΠΈΠ½Π°Π΅ΠΌ Π΅Π³ΠΎ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ long newRowId = db.update(DictionaryContract.DictionaryEntry.TABLE_NAME, values, DictionaryContract.DictionaryEntry.COLUMN_WORD + "= ?", new String[]{word}); // Π’Ρ‹Π²ΠΎΠ΄ΠΈΠΌ сообщСниС Π² ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠΌ случаС ΠΈΠ»ΠΈ ΠΏΡ€ΠΈ ошибкС if (newRowId == -1) { // Если ID -1, Π·Π½Π°Ρ‡ΠΈΡ‚ ΠΏΡ€ΠΎΠΈΠ·ΠΎΡˆΠ»Π° ошибка Toast.makeText(this, "Ошибка ΠΏΡ€ΠΈ сохранСнии ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Π‘Π»ΠΎΠ²ΠΎ " + "\"" + word + "\"" + " ΠΎΡ‚Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΎ", Toast.LENGTH_SHORT).show(); } } 

In table 4, the columns are word (text) , translation (text) , type (integer) and _id (integer) .

Before adding the type (integer ) column to the table, everything worked, and now when I try to update, the program crashes. What can be wrong?

This is what is displayed in the console.

 E/AndroidRuntime: FATAL EXCEPTION: main Process: test.proj1, PID: 2379 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) at android.view.View.performClick(View.java:5610) at android.view.View$PerformClick.run(View.java:22260) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5610) at android.view.View$PerformClick.run(View.java:22260) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.widget.CheckBox.isChecked()' on a null object reference at .ActivityEdit.onClickEditButton(ActivityEdit.java:170) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5610) at android.view.View$PerformClick.run(View.java:22260) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

  • one
    What error gives? - Sergey Gornostaev
  • Stack stack lay out - pavel163
  • Well, most likely you did not update the database, that is, your application still uses the old version of the database, in which this column does not exist yet. Uninstall and reinstall the application. But in order for everything to work correctly for users, you need to upgrade the version of the database and write a script to update the database if it is not enough to delete and recreate the database. - temq
  • The database has been updated, other methods for searching records with a new column work - user215435
  • Well, for this setpoint, your checkbox is null. There it is written that way - temq

0