title: java.lang.NullPointerException: Attempt to invoke virtual method on a null object reference. what should i do?
body: <p>I I have created an app that was working perfectly before I introduces ViewFlipper into it. I really need to use this, but now I'm stuck or this exception.</p>
  
  <p>frag_home.java</p>
  
  <pre><code>public class Frag_home extends Fragment {
  private String mParam1;
  private String mParam2;
  Animation fade_in, fade_out;
  ViewFlipper viewFlipper;
  
  private OnFragmentInteractionListener mListener;
  
  public Frag_home() {
      // Required empty public constructor
  }
  
  
  // TODO: Rename and change types and number of parameters
  public static Frag_home newInstance(String param1, String param2) {
      Frag_home fragment = new Frag_home();
      Bundle args = new Bundle();
      args.putString(ARG_PARAM1, param1);
      args.putString(ARG_PARAM2, param2);
      fragment.setArguments(args);
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      if (getArguments() != null) {
          mParam1 = getArguments().getString(ARG_PARAM1);
          mParam2 = getArguments().getString(ARG_PARAM2);
      }
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.fragment_frag_home, container, false);
  
      fade_in= AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in);
      fade_out=AnimationUtils.loadAnimation(getActivity(),R.anim.fade_out);
  
      viewFlipper.setAnimation(fade_in);
      viewFlipper.setAnimation(fade_out);
  
      viewFlipper.setAutoStart(true);
      viewFlipper.setFlipInterval(1000);
      viewFlipper.startFlipping();
  }
  
  // TODO: Rename method, update argument and hook method into UI event
  public void onButtonPressed(Uri uri) {
      if (mListener != null) {
          mListener.onFragmentInteraction(uri);
      }
  }
  
  @Override
  public void onAttach(Context context) {
      super.onAttach(context);
      if (context instanceof OnFragmentInteractionListener) {
          mListener = (OnFragmentInteractionListener) context;
      } else {
          throw new RuntimeException(context.toString()
                  + " must implement OnFragmentInteractionListener");
      }
  }
  
  @Override
  public void onDetach() {
      super.onDetach();
      mListener = null;
  }
  public interface OnFragmentInteractionListener {
      // TODO: Update argument type and name
      void onFragmentInteraction(Uri uri);
  }
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>04-09 18:29:02.196 27863-27863/com.example.aastha.trying E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.example.aastha.trying, PID: 27863
                                                                         java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ViewFlipper.setAnimation(android.view.animation.Animation)' on a null object reference
                                                                             at com.example.aastha.trying.Frag_home.onCreate(Frag_home.java:70)
                                                                             at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
                                                                             at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
                                                                             at android.support.v4.app.BackStackRecord.ensureFragmentsAreInitialized(BackStackRecord.java:1077)
                                                                             at android.support.v4.app.BackStackRecord.beginTransition(BackStackRecord.java:1032)
                                                                             at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:658)
                                                                             at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                                                                             at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
                                                                             at android.os.Handler.handleCallback(Handler.java:739)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                             at android.os.Looper.loop(Looper.java:145)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5832)
                                                                             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:1399)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  </code></pre>
  
  <p>The code above gives me this exception:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ViewFlipper.setAnimation(android.view.animation.Animation)' on a null object reference
  </code></pre>
  
  <p>How should i resolve this? Please help.</p>