title: Open Another Activity Using Fragment Button
body: <p>Okay so I've tried two types of code to get this to work and it keeps giving me force closes when I press the button to go into another Activity. I'm using a Fragment and there's a button  in that Fragments code but I can't seem to get it to work. I'm not an experienced Android developer but I'm trying my best to learn. </p>
  
  <p>Here's the Java code:</p>
  
  <p>1st Method</p>
  
  <pre><code>public class About extends Fragment {
  
      Intent intent;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.about, container, false);
  
          intent = new Intent(getActivity(), Contact_Developer.class);
          final Button button = (Button) rootView.findViewById(R.id.btnContactDev);
  
          button.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  startActivity(intent);
              }
          });
  
          return rootView;
      }
  }
  </code></pre>
  
  <p>2nd Method</p>
  
  <pre><code>public class About extends Fragment {
  
      public void onCreate (Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.about, container, false);
  
          Button button = (Button) rootView.findViewById(R.id.btnContactDev);
          button.setOnClickListener(new View.OnClickListener() {
  
             @Override
             public void onClick(View arg0) {
                Intent intent = new Intent(getActivity(), Contact_Developer.class);
                getActivity().startActivity(intent);
             }
          });
          return rootView;
      }
  }
  </code></pre>
  
  <p>I really don't know what's going on and why I'm getting force closes but if anyone could help me and explain a little what I did wrong that'd be more than enough</p>