I have some objects with a Spanned attribute. These are filled with HTML code including images.
On a button click I display the Spanned content in a TextView.
SOMETIMES (and I cannot reproduce this) I get this exception:
11-07 23:26:16.707: E/AndroidRuntime(23715): java.lang.NullPointerException
11-07 23:26:16.707: E/AndroidRuntime(23715): at android.text.SpannableStringBuilder.length(SpannableStringBuilder.java:126)
11-07 23:26:16.707: E/AndroidRuntime(23715): at android.widget.TextView.setText(TextView.java:2631)
11-07 23:26:16.707: E/AndroidRuntime(23715): at android.widget.TextView.setText(TextView.java:2598)
11-07 23:26:16.707: E/AndroidRuntime(23715): at android.widget.TextView.setText(TextView.java:2573)
11-07 23:26:16.707: E/AndroidRuntime(23715): at [...]
In the following second line, the exception is thrown (so the Spanned isnt null!):
if(hasSpanned){
tv.setText(ans.getTxtS());
}
Can anybody help me?
Either
tvis null oransis null. You can write a little test to figure out which one it is by inserting the following code before your if statment:When you figure our which one it is, go through your code and check to make sure you’ve initialized them.