Can someone explain why this is crashing? I am doing it the exact same way twice. My logcat says its the int FN line so if I comment out the int FN line, it will continue on. But I need to get both tags, not just one.
I set my ID in my Resources
<resources>
<item type="id" name="fromNumberTag" />
<item type="id" name="contactImageTag"/>
</resources>
I set my tags in my adapter.
// SET OUR DATA FROM OUR CURSOR
String phone_number = list.getString( list.getColumnIndex("phoneNumber"));
from.setTag(R.id.fromNumberTag,list.getString(list.getColumnIndex("contactId")));
contactimage.setTag(R.id.contactImageTag, phone_number);
Then I try to get the tags. (THIS IS WHERE IT IS CRASHING AT)
int cid = Integer.parseInt(listText.getTag(R.id.fromNumberTag).toString());
int fn = Integer.parseInt(listText.getTag(R.id.contactImageTag).toString()); // LOGCAT SAYS THIS LINE IS WHERE ERROR OCCURS
My logcat
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at myapp.myapp.MainActivity$2.onItemClick(MainActivity.java:272)
You set the tags on two different objects (from
and contactimage
), but trying to get the tags from only one object (listText
). Maybe you set one tag on the wrong object or read one tag from the wrong object?