Reputation: 5
I'm trying to pass a string value from my listview adapter to my fragment using the following code but I get a null pointer exception. Breaking it down told me that the error is in calling the method, but I don't see anything wrong
public void onClick(View v)
{
String text = myList.get(position);
resetArrbg();
arrBgcolor[position] = true;
DevFragment def = new DevFragment();
def.clicked(text);
}
The error is definitely in the last two lines, because if I replace them with a Toast using the text variable, it works The corresponding method in the fragment is
public void clicked(String arg1)
{
globalString == arg1;
}
Upvotes: 0
Views: 101
Reputation: 17580
globalString == arg1;
In above lines you are comparing String objects instead of assigning it. I think you should replace this by-
globalString = arg1;
Upvotes: 0
Reputation: 157457
globalString == arg1;
you want to assing the String not compare its address
globalString = arg1;
Upvotes: 5