title: setOnClickListener FloatingActionButton on Fragment Error
body: <p>I'm new to <code>Fragment</code> and <code>FloatingActionButtons</code> in Android Studio. I have been trying to get the <code>FloatingActionButton</code> with a <code>setOnClickListener</code> but every time I run the program I get an error message which I can't figure out how to fix. I know that there are a lot other questions on here with the same problem although I have been through them and still couldn't figure it out, I am a complete newbie at this and thank you in advance for all your help.</p>
  
  <p>Here is the XML code for the <code>FloatingActionButton</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  xmlns:fab="http://schemas.android.com/apk/res-auto"
  tools:context="com.example.user.health.IceOneActivity"&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:popupTheme="@style/AppTheme.PopupOverlay" /&gt;
  
  &lt;/android.support.design.widget.AppBarLayout&gt;
  
  &lt;include layout="@layout/content_ice_one" /&gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/viewpager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;
  
  &lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/editInfo"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="230dp"
      android:layout_gravity="bottom|end"
      android:layout_marginRight="@dimen/fab_margin"
      android:visibility="invisible"
      app:backgroundTint="@color/colorFAB3"
      app:elevation="6dp"
      app:pressedTranslationZ="12dp"
      app:fab_title="Edit"
      android:src="@drawable/ic_create_white_24dp" /&gt;
  &lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/saveInfo"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="160dp"
      android:layout_gravity="bottom|end"
      android:layout_marginRight="@dimen/fab_margin"
      android:visibility="invisible"
      app:elevation="6dp"
      app:backgroundTint="@color/colorFAB2"
      app:pressedTranslationZ="12dp"
      app:fab_title="Save"
      android:src="@drawable/ic_save_white_24dp" /&gt;
  &lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/showInfo"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="90dp"
      android:layout_gravity="bottom|end"
      android:layout_marginRight="@dimen/fab_margin"
      android:visibility="invisible"
      app:elevation="6dp"
      app:backgroundTint="@color/colorFAB1"
      app:pressedTranslationZ="12dp"
      fab:fab_title="Done"
      android:src="@drawable/ic_check_white_24dp" /&gt;
  &lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/moreInfo"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom|end"
      app:elevation="6dp"
      app:backgroundTint="@color/colorAccent"
      app:pressedTranslationZ="12dp"
      android:layout_margin="@dimen/fab_margin"
      android:src="@drawable/ic_add_white_24dp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the java activity:</p>
  
  <pre><code>public class IceOneActivity extends Fragment implements View.OnClickListener {
  
  private Boolean isFabOpen = false;
  private FloatingActionButton moreInfo,saveInfo,editInfo,showInfo;
  private Animation fab_open,fab_close,rotate_forward,rotate_backward;
  
  public IceOneActivity() {
      // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View iceOneView = inflater.inflate(R.layout.content_ice_one, container, false);
  
      //myFragmentView
      moreInfo = (FloatingActionButton) inflater.inflate(R.layout.content_ice_one, container, false).findViewById(R.id.moreInfo);
      saveInfo = (FloatingActionButton) inflater.inflate(R.layout.content_ice_one, container, false).findViewById(R.id.saveInfo);
      editInfo = (FloatingActionButton) inflater.inflate(R.layout.content_ice_one, container, false).findViewById(R.id.editInfo);
      showInfo = (FloatingActionButton) inflater.inflate(R.layout.content_ice_one, container, false).findViewById(R.id.showInfo);
      fab_open = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_open);
      fab_close = AnimationUtils.loadAnimation(getActivity(),R.anim.fab_close);
      rotate_forward = AnimationUtils.loadAnimation(getActivity(),R.anim.rotate_forward);
      rotate_backward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_backward);
      moreInfo.setOnClickListener(this);
      saveInfo.setOnClickListener(this);
      editInfo.setOnClickListener(this);
      showInfo.setOnClickListener(this);
  
      return iceOneView;
  }
  
  @Override
  public void onClick(View v) {
      int id = v.getId();
      switch (id){
          case R.id.moreInfo:
  
              animateFAB();
              break;
          case R.id.saveInfo:
  
              Log.d("1", "Fab 1");
              break;
          case R.id.editInfo:
  
              Log.d("2", "Fab 2");
              break;
          case R.id.showInfo:
  
              Log.d("3", "Fab 3");
              break;
      }
  }
  </code></pre>
  
  <p>Here is the Logcat of the application when I try and run the activity:</p>
  
  <pre><code>Process: com.example.user.health, PID: 13237
  java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
  at com.example.user.health.IceOneActivity.onCreateView(IceOneActivity.java:44)
  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
  at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
  at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
  at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5966)
  at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:610)
  at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:677)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5966)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5966)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5966)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5966)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5966)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2693)
  at android.view.View.measure(View.java:18893)
  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2192)
  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1271)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1510)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1162)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6229)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
  at android.view.Choreographer.doCallbacks(Choreographer.java:676)
  at android.view.Choreographer.doFrame(Choreographer.java:606)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:168)
  at android.app.ActivityThread.main(ActivityThread.java:5845)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
  </code></pre>