当我在recyclerView ..内的卡片视图中单击开关契约时,我想在SQLite列中插入值1,但是当我单击switchCompact时,得到NullPointeException。 enter image description here 预先感谢..我是Android的新手
orderListAdapter.java
public void onBindViewHolder(@NonNull final orderListHolder holder,final int position) {
final orderbook orderbook = orderbooklist.get(position);
holder.orderno.setText(orderbook.orderNo + " ");
holder.customerName.setText(orderbook.customerName);
holder.itemName.setText(orderbook.itemName);
holder.workCompleteSwicth.setOnCheckedchangelistener(new CompoundButton.OnCheckedchangelistener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton,boolean b) {
if(holder.workCompleteSwicth.isChecked()) {
myDb.InsertWorkComplete(1);
}
}
});
DatabaseHelper.java
public void InsertWorkComplete( int isWorkComplete)
{
SQLiteDatabase db=this.getwritabledatabase();
Contentvalues contentvalues=new Contentvalues();
contentvalues.put(COLUMN_ISWORKCOMPLETE,isWorkComplete);
db.update(TABLE_NAME,contentvalues,null,null);
}
logcat:-
Process: com.example.android.saffrondesigner,PID: 5359
java.lang.NullPointerException
at com.example.android.saffrondesigner.orderListAdapter$1.onCheckedChanged(orderListAdapter.java:60)
at android.widget.CompoundButton.setChecked(CompoundButton.java:127)
at androidx.appcompat.widget.SwitchCompat.setChecked(SwitchCompat.java:1060)
at androidx.appcompat.widget.SwitchCompat.toggle(SwitchCompat.java:1055)
at android.widget.CompoundButton.performClick(CompoundButton.java:99)
at android.view.View$PerformClick.run(View.java:18797)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.activityThread.main(activityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)