Tim Holloway wrote:Don't despair. It's not that hard and it does work reliably. There's probably some simple mistake you made that, when fixed, magically makes the whole thing work. That's usually how it is for me. Although it usually takes 3-4 days of swearing and finally getting a junior programmer to point out I'm missing something trivial.
Being that this is Android, probably one of the trickiest things to know is what methods get called when, since Android does much of the calling, not your code. Adding some tracing statements to the log (or IDE breakpoints) can help with that.
If you're new to Java, though, learning Java AND Android at the same time is going to be harder than learning just Java.
Tim Holloway wrote:I expected that you would say that.
But all that means to me is that either you've accidentally created more than one instance of your SQLiteDBOpenHelper class and haven't initialized the one you're currently using, or you've managed to nuke/re-initialize the one you were using.
Paul Clapham wrote:
Tim Holloway wrote:The way I read that is that you didn't create the database itself.
I agree, it looks like the problem is to do with accessing the database rather than with processing the query. Notice that there's a method named getReadableDatabase near the top of the stack trace, higher than deleteCustomer. And the error appears to be related to finding the location of the database ("getDatabasePath").
If my theory is correct then executing any query should have the same result, or maybe only any query which wants to update the database.
Randy Tong wrote:I think you'r pasting log message instead of the error.The error should look similar to this
Randy Tong wrote:
adrian rowlands wrote:the second one was what showed up in the stack trace
No, that's not the stacktrace. The stacktrace is the error message which made your app crashed. You can find the stacktrace in logcat window (if you using Android Studio).
Randy Tong wrote:Why do you need to call deleteCustomer twice ? Between, don't forget to post your stacktrace.
Randy Tong wrote:paste your latest code and the stacktrace.
Randy Tong wrote:Here the ideas:
1. Create a delete function (Eg: removeItem ) in CustomerDB class.
2. When the delete button is clicked, pass the id to removeItem method.
3. Execute the delete query in removeItem method.
4. Refresh recyclerView.