The following code generates NullPointerException
in Android.
searchResults.setText(searchResultString);
Where:
- searchResults is a TextView
- searchResultString is a String
Can somebody list out the possible reasons why this may be happening?
The following code generates NullPointerException
in Android.
searchResults.setText(searchResultString);
Where:
Can somebody list out the possible reasons why this may be happening?
So your textView not binding or attaching correctly. Other wise setText expecting string and your codes should work. Check where you bind your searchResult object.
Make sure that the searchResults TextView is initialized in Android. This is a very common programming mistake in Android.
You can initialize it like this.
TextView searchResults;
searchResults = (TextView) findViewById(R.id.searchResultsTextView);
Let me know if this solution works out.
Just make sure that the binding between the java file and the xml file is done properly for the given text view.