i am trying to set up a delete button to delete a customer from a table, the customers are displayed in card views using a recycler view so each customer will have their own delete button, the customer information are displayed using textviews. i need to pass the customer id to the delete method i order to search the table for that specific id to delete. how do i pass the data succesfully?
this is what iver currently got to try and pass the data i need
public void onBindViewHolder(@NonNull MyHolder holder, final int position) {
holder.idText.setText(String.valueOf(id.get(position)));
holder.nameText.setText(String.valueOf(name.get(position)));
holder.surnameText.setText(String.valueOf(surname.get(position)));
holder.add1Text.setText(String.valueOf(add1.get(position)));
holder.add2Text.setText(String.valueOf(add2.get(position)));
holder.add3Text.setText(String.valueOf(add3.get(position)));
holder.postCodeText.setText(String.valueOf(postCode.get(position)));
holder.phoneNumberText.setText(String.valueOf(phoneNumber.get(position)));
holder.emailText.setText(String.valueOf(email.get(position)));
GlobalVars.id = holder.idText.getText().toString();
holder.delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
db.deleteCustomer(GlobalVars.id);
}
});
}
this is my delete method
public long deleteCustomer(String id)
{
SQLiteDatabase db = this.getWriteableDatabase();
ContentValues idValue = new ContentValues();
idValue.put(CUSTOMER_ID, id);
return db.delete(TABLE_NAME, "where Customer_ID = " + idValue, null);
}
when i run the app it displays the customers and the buttons but when i click any of the buttons i get a blank screen then it returns to the login screen i have.
this is the errors that show up in logcat
2021-05-01 12:16:26.212 18729-18729/com.example.rowlandsflooringapp E/Zygote: isWhitelistProcess - Process is Whitelisted 2021-05-01 12:16:26.212 18729-18729/com.example.rowlandsflooringapp E/Zygote: accessInfo : 1 2021-05-01 12:16:26.244 18729-18729/com.example.rowlandsflooringapp E/andsflooringap: Unknown bits set in runtime_flags: 0x8000 2021-05-01 12:16:55.186 18729-18729/com.example.rowlandsflooringapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.rowlandsflooringapp, PID: 18729 java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:445) at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:415) at com.example.rowlandsflooringapp.CustomerDB.deleteCustomer(CustomerDB.java:70) at com.example.rowlandsflooringapp.CustomerAdapter$1.onClick(CustomerAdapter.java:73) at android.view.View.performClick(View.java:7862) at android.widget.TextView.performClick(TextView.java:15004) at android.view.View.performClickInternal(View.java:7831) at android.view.View.access$3600(View.java:879) at android.view.View$PerformClick.run(View.java:29359) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:8167) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
from How do i pass data to another method
No comments:
Post a Comment