Creating new SpannableStringBuilder returns null

Here is my unit test. Somehow when I create instantiate SpannableStringBuilder instance with a non-null string argument, it appears to be null. What's wrong with this code?

public class CardNumberTextWatcherTest {

private CardNumberTextWatcher watcher;

public void setUp() throws Exception {
    watcher = new CardNumberTextWatcher();

public void afterTextChanged_cardNumberDividedWithSpaces() {
    assertTransformText("1111222233334444", "1111 2222 3333 4444");

private void assertTransformText(final String testStr,
                                 final String expectedStr) {
    final CardNumberTextWatcher watcher = new CardNumberTextWatcher();
    final Editable actualStr = new SpannableStringBuilder(testStr);
    // When I debug I see that actualStr value is null. Therefore test 
    //doesn't pass. What's the problem?
    assertEquals(expectedStr, actualStr.toString());


The problem was in the testing directory. As soon as SpannableStringBuilder is a part of Android SDK, it couldn't be resolved in regular JUnit test directory. When I moved my class to androidTest directory, everything started to work as expected.

android.text.SpannableStringBuilder.<init> java code examples , final SpannableStringBuilder sb = new SpannableStringBuilder("your text here"); How to make part of the text Bold in android at runtime? Is it possible to change the text color in a string to multiple colors in Java? getCues() firstNormalCue = cue; } else if (normalCueTextBuilder == null) { normalCueTextBuilder = new� A constructor used when creating managed representations of JNI objects; called by the runtime. SpannableStringBuilder(String) SpannableStringBuilder(String) Create a new SpannableStringBuilder containing a copy of the specified text, including its spans if any. SpannableStringBuilder(String, Int32, Int32) SpannableStringBuilder(String, Int32

You are calling actualStr.toString() which is what the assertion is comparing with, not actualStr itself so look for routes through SpannableStringBuilder to see what could result in null from toString(). Probably testStr is null.

android.text.SpannableStringBuilder.append java code examples , CharSequence text;new SpannableStringBuilder(text); Smart code subject) { if (sender == null) { return subject; } SpannableStringBuilder summary = new SpannableStringBuilder to create String with multiple fonts/text sizes etc Example ? Background Suppose I use SpannableStringBuilder to append multiple stuff into it, and one of them is string that I format from the strings.xml file, which has a span inside: SpannableStringBuilder


Using Robolectric resolves the issue.

SpannableStringBuilder, This is the class for text whose content and markup can both be changed. <init >(). Create a new SpannableStringBuilder with empty contents. 3 Creating new SpannableStringBuilder returns null Dec 19 '17. 3 How can I know that Android SharedPreferences are saved successfully? Apr 26 '17.

SpannableStringBuilder | J2ObjC, This is the class for text whose content and markup can both be changed. Create a new SpannableStringBuilder with empty contents. public static ICharSequence Parse( Context context, List<IconFontDescriptorWrapper> iconFontDescriptors, string text, TextView target) { context = context.ApplicationContext; // Analyse the text and replace {} blocks with the appropriate character // Retain all transformations in the accumulator SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(text

Java Code Examples for android.text.SpannableStringBuilder, isEmpty(mLinkText)) { SpannableStringBuilder spannableLinkText = new editor = MarkwonEditor.create(markwon); final SpannableStringBuilder builder = new null ? override : (String) getTag(); SpannableStringBuilder builder = new @param line All text fields within this line will be added to the returned Spannable. Prints formatted representations of objects to a text-output stream. This class implements all of th

Java Code Examples for, If sub-string is null, entire string will be typefaced as bold and returned. getNodeText())) { return null; } SpannableStringBuilder updatedString = new + 1)).append("\n"); } } } return; } catch (Exception e) { Logger.e("non form url� // This test failed before #685 was fixed (throws a InvocationTargetException) public void testStartImg() throws NoSuchMethodException, IllegalAccessException { SpannableStringBuilder text = new SpannableStringBuilder(); Attributes attributes = new AttributesImpl(); HtmlToSpannedConverter converter = new HtmlToSpannedConverter(null, null, null

  • Can you please provide the stack trace or test output?
  • Please share your exception stack trace so we can help you
  • Thank you, exactly the same issue. Actually don't know, why this question was so minused.