1

I wanted to try out WizarDroid library in my app. But since I am fairly inexperienced with inflators I got stuck on this error for hours.

I get a NullPointerException while trying to findViewById and I can't figure out why.

public class WizardStep1 extends WizardStep {

    //Wire the layout to the step
    public WizardStep1() {
    }

    //Set your layout here
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.wizard, container, false);
        TextView tv = (TextView) v.findViewById(R.id.wizard_textView); // tv = null
        tv.setText("This is an example of Step 1 in the wizard. Press the Next " + // NullPointerException gets thrown here
                "button to proceed to the next step. Hit the back button to go back to the calling activity.");

        return v;
    }
}

So TextView tv is null for some reason. I can't figure this out because I clearly defined it in XML R.layout.wizard

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/wizard_textView"
        android:layout_marginTop="10dp"
        android:textSize="20dp"
        android:text="gtsets" />
</LinearLayout>

This code is also from their documentation so it just further confuses me :/

Edit: Here's wizardStartup class :

public class wizardStartup extends BasicWizardLayout {

    /**
     * Note that initially BasicWizardLayout inherits from {@link android.support.v4.app.Fragment} and therefore you must have an empty constructor
     */
    public wizardStartup() {
        super();
    }

    //You must override this method and create a wizard flow by
    //using WizardFlow.Builder as shown in this example
    @Override
    public WizardFlow onSetup() {
        /* Optionally, you can set different labels for the control buttons
        setNextButtonLabel("Advance");
        setBackButtonLabel("Return");
        setFinishButtonLabel("Finalize"); */

        return new WizardFlow.Builder()
                .addStep(WizardStep1.class)           //Add your steps in the order you want them
                .addStep(WizardStep2.class)           //to appear and eventually call create()
                .create();                              //to create the wizard flow.
    }
}

LogCat :

07-15 17:58:05.491 10299-10299/ba.imasoft.dfms.app E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at ba.imasoft.dfms.app.wizards.steps.WizardStep1.onCreateView(WizardStep1.java:28)

Line 28 is 'tv.setText("This'..

If I comment out the lines that contain tv variable It works but not the way It's supposed to.. I need to edit the view for each step.

tv = null proof...

watches

Muhamed Krlić
  • 1,462
  • 2
  • 16
  • 25

1 Answers1

0

The problem was bizarrely strange..

Anyway all I did is change wizard.xml to wizard_step.xml figured it was using wizard.xml as something else in the library hmm..

It worked.

Muhamed Krlić
  • 1,462
  • 2
  • 16
  • 25
  • 1
    That is very much correct! The library already has a layout file named `wizard.xml` as you can see [here](https://github.com/Nimrodda/WizarDroid/blob/develop/wizardroid/src/main/res/layout/wizard.xml). I will add it to the FAQ and rename this file in future releases. – Nimrod Dayan Jul 19 '14 at 07:22