Skip to content
Advertisement

Android: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String java.lang.Object.toString()’ on a null object reference

Facing a problem with a practice app I’m working on. I’m facing a NullPointerException problem relating to the toString method. Being new to android app development, I’m unsure of the exact cause even after my research into this. Hence I ask for someone who is more familiar with the stack trace to kindly help me out.

Note: The error occurs when I click on the listview entry to access an edit page for the diary entry. However it doesn’t seem to go to the edit page at all.

Below you’ll find my activity code it occurs on and the stack trace.

Activity code:

JavaScript

Here is my stack trace that I see:

JavaScript

Any help towards a solution will be appreciated.

EDIT:

So after staring back and forth from the code between the database and the activity it interacts with, I managed to get it working again. Below is what I did in the exact order:

  1. I realized that I had a date field that was receiving no data, rectified that.
  2. Cleaned the project.
  3. Restarted Android Studio (basically stopping all the operations of the development environment).
  4. Uninstalled the app from my dev phone.
  5. Restarted android studio and re-installed the app.
  6. I somehow works =_=, yes it is magic.

Honestly I’ve no idea which step actually solved it. I’m guessing it was the date field in the database that was messing things up for me while it was receiving no data.

Advertisement

Answer

The array in your ArrayAdapter contains at least one entry that is null. There must be no nulls there.

The array is populated in getDiaryDBDataList() so the problem is also there.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement