-2

I am trying to build a dashboard-layout in android by following this tutorial:

http://www.technotalkative.com/android-dashboard-design-pattern-implementation/

In this tutorial an abstract class will be created which will define event handlers for the buttons: Home and Feedback and other methods. Each activity extends this super class, since the home and feedback button must be shown in each activity (except the main/home activity)

There is this method defined in the abstract class, which makes the home/feedback button dependent on the activity

public void setHeader(String title, boolean btnHomeVisible, boolean btnFeedbackVisible)
    {
      ViewStub stub = (ViewStub) findViewById(R.id.vsHeader);
      View inflated = stub.inflate();

      TextView txtTitle = (TextView) inflated.findViewById(R.id.txtHeading);
      txtTitle.setText(title);

      Button btnHome = (Button) inflated.findViewById(R.id.btnHome);
      if(!btnHomeVisible)
       btnHome.setVisibility(View.INVISIBLE);

      Button btnFeedback = (Button) inflated.findViewById(R.id.btnFeedback);
      if(!btnFeedbackVisible)
       btnFeedback.setVisibility(View.INVISIBLE);
    }

For example, the home activity, where the dashboard layout is shown, doesn't need to show the home button, because it is already the home activity, however if another activity is opened from the dashboard, then I want to make the home button visible like this:

public class Activity_Eclair extends DashBoardActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eclair);         

           //Passing true in order to make the home button visible
            setHeader(getString(R.string.EclairActivityTitle), true, true);
        }
    }

However, the activity won't open because I always get a NullPointerException and I don't know why:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.ViewStub.inflate()' on a null object reference

The problem is that the stub variable in the setHeader-method is null, but I don't know why:

  ViewStub stub = (ViewStub) findViewById(R.id.vsHeader);
  View inflated = stub.inflate()
NoName123
  • 137
  • 5
  • 20

1 Answers1

0

I found my error, I just forgot to declare the ViewStub in the activity_eclair:

<ViewStub
        android:id="@+id/vsHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inflatedId="@+id/header"
        android:layout="@layout/header" />
NoName123
  • 137
  • 5
  • 20