title: Android bug - Binary XML file line #1: Error inflating class fragment
body: <p>I am attempting to implement a to-do list using listview and listview adapter but have run into several runtime exceptions that I can't overcome. Logcat says that I am trying to invoke findViewById on a null object reference (line 24 = private Spinner spinner_priority;). However, the id for the spinner is spinnerPriority and findViewById(R.id.spinnerPriority) is invoked correctly. </p>
  
  <p>I haven't changed the default ToDoActivity.java implementation except for extending ToDoActivity from FragmentActivity instead of AppCombatActivity and importing android.support.v4.app.FragmentActivity instead of android.app.FragmentActivity. </p>
  
  <p>Any insights as to why the app is crashing?</p>
  
  <p>Logcat:</p>
  
  <pre><code>08-27 00:45:58.209  11873-11873/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.ttse.final_tse, PID: 11873
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ttse.final_tse/com.ttse.final_tse.ToDoActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
              at android.app.ActivityThread.access$800(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
       Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
              at android.app.Activity.setContentView(Activity.java:2145)
              at com.ttse.final_tse.ToDoActivity.onCreate(ToDoActivity.java:14)
              at android.app.Activity.performCreate(Activity.java:5990)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
              at android.app.ActivityThread.access$800(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v4.app.FragmentActivity.findViewById(int)' on a null object reference
              at com.ttse.final_tse.ToDoActivityFragment.&lt;init&gt;(ToDoActivityFragment.java:24)
              at java.lang.reflect.Constructor.newInstance(Native Method)
              at java.lang.Class.newInstance(Class.java:1606)
              at android.support.v4.app.Fragment.instantiate(Fragment.java:421)
              at android.support.v4.app.Fragment.instantiate(Fragment.java:396)
              at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2162)
              at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
              at android.app.Activity.setContentView(Activity.java:2145)
              at com.ttse.final_tse.ToDoActivity.onCreate(ToDoActivity.java:14)
              at android.app.Activity.performCreate(Activity.java:5990)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
              at android.app.ActivityThread.access$800(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  
  <p>ToDoActivity.java</p>
  
  <pre><code>package com.ttse.final_tse;
  
  import android.support.v4.app.FragmentActivity;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  
  public class ToDoActivity extends FragmentActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_to_do);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_to_do, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>activity_to_do.xml</p>
  
  <pre><code>&lt;fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/fragment"
            android:name="com.ttse.final_tse.ToDoActivityFragment"
            tools:layout="@layout/fragment_to_do"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/&gt;
  </code></pre>
  
  <p>ToDoActivityFragment.java</p>
  
  <pre><code>package com.ttse.final_tse;
  
  import android.app.DialogFragment;
  import android.support.v4.app.Fragment;
  import android.os.Bundle;
  import android.text.TextUtils;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  import java.util.ArrayList;
  import java.util.List;
  
  public class ToDoActivityFragment extends Fragment {
      private List&lt;Task&gt; list_tasks = new ArrayList&lt;Task&gt;();
      private ArrayAdapter&lt;Task&gt; list_adapter = null;
      private final EditText editText_title = (EditText)getActivity().findViewById(R.id.editTextTitle);
      private Spinner spinner_priority;
      private Button button_datepicker;
      private final TextView textView_date = (TextView)getActivity().findViewById(R.id.textViewDate);
      private EditText editText_shortDescr;
      private Button button_save;
  
      public ToDoActivityFragment() {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_to_do, container, false);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          // To-Do ListView
          ListView list = (ListView)getActivity().findViewById(R.id.listViewToDo);
          list_adapter = new ArrayAdapter&lt;Task&gt;(getActivity(), android.R.layout.simple_list_item_1, list_tasks);
          list.setAdapter(list_adapter);
  
          // Priority Spinner
          spinner_priority = (Spinner)getActivity().findViewById(R.id.spinnerPriority);
          ArrayAdapter&lt;CharSequence&gt; spinner_adapter = ArrayAdapter.createFromResource(getActivity(), R.array.priority_array, android.R.layout.simple_spinner_item);
          spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner_priority.setAdapter(spinner_adapter);
  
          spinner_priority.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
              }
          });
  
          // Datepicker Button
          button_datepicker = (Button)getActivity().findViewById(R.id.buttonDatepicker);
          button_datepicker.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  showDatePickerDialog(v);
              }
          });
  
          // Short Description EditText
          editText_shortDescr = (EditText)getActivity().findViewById(R.id.editTextShortDescr);
  
          // Save Button
          button_save = (Button)getActivity().findViewById(R.id.buttonSave);
          button_save.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if(TextUtils.isEmpty(editText_title.getText()) || TextUtils.isEmpty(textView_date.getText())) {
                      Toast.makeText(getActivity(), "Please set to-do title and due date", Toast.LENGTH_SHORT).show();
                      return;
                  }
                  onSave();
              }
          });
      }
  
      private void showDatePickerDialog(View v) {
          DialogFragment date_picker = new DatePickerFragment();
          // show datepicker fragment on screen
          date_picker.show(getActivity().getFragmentManager(), "datePicker");
      }
  
      private void onSave() {
          Task task = new Task();
          task.setTitle(editText_title.getText().toString());
          task.setPriority(spinner_priority.getSelectedItem().toString());
          task.setDueDate(textView_date.getText().toString());
          task.setShortDescr(editText_shortDescr.getText().toString());
          list_adapter.add(task);
          list_adapter.notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>fragment_to_do.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:paddingLeft="@dimen/activity_horizontal_margin"
                  android:paddingRight="@dimen/activity_horizontal_margin"
                  android:paddingTop="@dimen/activity_vertical_margin"
                  android:paddingBottom="@dimen/activity_vertical_margin"
                  tools:context=".ToDoActivityFragment"&gt;
      &lt;ListView
          android:id="@+id/listViewToDo"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="10"&gt;
  
      &lt;/ListView&gt;
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:orientation="vertical"
          android:layout_weight="7"&gt;
          &lt;EditText
              android:id="@+id/editTextTitle"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="Title..."/&gt;
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"&gt;
              &lt;TextView
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="3"
                  android:text="Priority Level:"
                  android:layout_marginTop="5dp"/&gt;
              &lt;Spinner
                  android:id="@+id/spinnerPriority"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="4"
                  android:spinnerMode="dropdown"
                  android:layout_marginTop="5dp"/&gt;
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="4"
                  android:orientation="vertical"&gt;
                  &lt;Button
                      android:id="@+id/buttonDatepicker"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="@string/pick_date"/&gt;
                  &lt;TextView
                      android:id="@+id/textViewDate"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"/&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
          &lt;EditText
              android:id="@+id/editTextShortDescr"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="Short description..."
              android:textSize="14sp"/&gt;
          &lt;Button
              android:id="@+id/buttonSave"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/text_save"
              android:layout_gravity="center"/&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>DatePickerFragment.java</p>
  
  <pre><code>package com.ttse.final_tse;
  
  import android.app.DatePickerDialog;
  import android.app.Dialog;
  import android.app.DialogFragment;
  import android.os.Bundle;
  import android.widget.DatePicker;
  import android.widget.TextView;
  import java.util.Calendar;
  
  public class DatePickerFragment extends DialogFragment
          implements DatePickerDialog.OnDateSetListener {
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          final Calendar c = Calendar.getInstance();
          int year = c.get(Calendar.YEAR);
          int month = c.get(Calendar.MONTH);
          int day = c.get(Calendar.DAY_OF_MONTH);
          return new DatePickerDialog(getActivity(), this, year, month, day);
      }
  
      public void onDateSet(DatePicker view, int year, int month, int day) {
          TextView textView_date = (TextView)getActivity().findViewById(R.id.textViewDate);
          textView_date.setText(new StringBuilder()
                  .append(month + 1).append("/").append(day).append("/")
                  .append(year));
      }
  }
  </code></pre>
  
  <p>Task.java</p>
  
  <pre><code>package com.ttse.final_tse;
  
  public class Task {
      private String mTitle;
      private String mDueDate;
      private String mPriority;
      private String mShortDescr;
  
      public String getTitle() {
          return mTitle;
      }
  
      public void setTitle(String title) {
          mTitle = title;
      }
  
      public String getDueDate() {
          return mDueDate;
      }
  
      public void setDueDate(String dueDate) {
          mDueDate = dueDate;
      }
  
      public String getPriority() {
          return mPriority;
      }
  
      public void setPriority(String priority) {
          mPriority = priority;
      }
  
      public String getShortDescr() {
          return mShortDescr;
      }
  
      public void setShortDescr(String shortDescr) {
          mShortDescr = shortDescr;
      }
  }
  </code></pre>