TextSwitcher NullPointer errors

Viewed 3179

I am really stuck on this. I am trying to do a simple textswitcher which will increment a quantity and update a price based on the quantity. Right now in my xml i have something like a TextView within a TextSwitcher just to increment the quantity. I get the textview with findViewById(R.id.quantity).

so this is what i have to find to setup the increment quantity ( I am implemementing ViewFactory)

switcher = (TextSwitcher) findViewById(R.id.switcher);
switcher.setFactory(this);
quantity = (TextView) findViewById(R.id.quantity);

I am also overriding the makeView()

@Override
     public View makeView() {
        return quantity;
    }

Also when an increment button is pressed i increment the counter and set the text on the switcher to the current count. Like this:

switcher.setText(String.valueOf(currentQuantity));

Can someone let me know what I am doing wrong?? I keep getting my nullpointer at this line:

switcher.setFactory(this);

Here is the XML snippet:

<TextSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/switcher">
            <TextView android:text="TextView" android:id="@+id/quantity" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
        </TextSwitcher>
4 Answers
Related