title: Android Fragment cannot resolve add method
body: <p>I'm kinda new on Android development. I've been watching videos from Udemy and it seems some of codes are outdated, which lead errors. When I try to add my PlaceholderFragment object to transaction, it says <strong>"Cannot resolve method add.."</strong>,in addition to that, at the else statement it says <strong>"Incompatible types"</strong>.However the <strong>taskFragment</strong> object is inheriting from the Fragment class and <strong>findFragmentByTag</strong> returns <strong>Fragment</strong> type. Here is the structure of code. </p>
  
  <p>Here I try use getSupportFragmentManager method to begin transaction.</p>
  
  <pre><code> @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      if (savedInstanceState == null) {
          taskFragment = new PlaceholderFragment();
          getSupportFragmentManager().beginTransaction().add(taskFragment, "MyFragment").commit();
  
      } else {
          taskFragment = getSupportFragmentManager().findFragmentByTag("MyFragment");
      }
      taskFragment.startTask();
  }
  </code></pre>
  
  <p>I have a class which extends Fragment: </p>
  
  <pre><code>public static class PlaceholderFragment extends Fragment {
  
      TechCrunchTask downloadTask;
  
      public PlaceholderFragment() {
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          setRetainInstance(true);
      }
  
      public void startTask() {
          if (downloadTask != null)
              downloadTask.cancel(true);
          else {
              downloadTask = new TechCrunchTask();
              downloadTask.execute();
          }
      }
  
  }
  </code></pre>
  
  <p>TechCrunchTask class is like this. 'L' is a custom class which logs the messages and shows toasts. It is irrelevant I assume.</p>
  
  <pre><code> public static class TechCrunchTask extends AsyncTask&lt;Void, Void, Void&gt; {
      @Override
      protected Void doInBackground(Void... params) {
          String downloadURL = "http://http://feeds.feedburner.com/techcrunch/android?format=xml";
          try {
              URL url = new URL(downloadURL);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              connection.setRequestMethod("GET");
              InputStream inputStream = connection.getInputStream();
              ProcessXML(inputStream);
          } catch (Exception e) {
              L.m(e + "");
          }
      }
  </code></pre>
  
  <p>This is the ProcessXML method:</p>
  
  <pre><code>  public void ProcessXML(InputStream inputStream) throws Exception {
          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
          Document xmlDocument = documentBuilder.parse(inputStream);
          Element rootElement = xmlDocument.getDocumentElement();
          L.m("" + rootElement.getTagName());
  
      }
  </code></pre>
  
  <p>Here is the list of imported packages:</p>
  
  <pre><code>import android.app.Activity;
  import android.app.Fragment;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v7.app.ActionBarActivity;
  import android.support.v7.app.AppCompatActivity;
  import android.view.Menu;
  import android.view.MenuItem;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.xml.sax.Parser;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.lang.annotation.ElementType;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;
  </code></pre>
  
  <p>And this is the inside of the build.gradle</p>
  
  <pre><code>dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:+'
  }
  </code></pre>
  
  <p>I guess this is about the version of support class. Mine is v7 as you see. How these can be solved. Thanks for help!</p>