Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to add a fragment to my fragment container FrameLayout
    primarykey
    data
    text
    <p>I have created an xml file called editor.xml which contains a FrameLayout. In my main activity I am trying to add my custom fragment to my FrameLayout.</p> <p>The error I receive when trying to add my fragment is:</p> <p>The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, editorFrag)</p> <p>However my editorFrag extends Fragment so I am confused on why this is happening. Below is my code for the files I have mentioned. Any help is appreciated.</p> <p>Editor.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <p>editorFrag.java</p> <pre><code>public class editorFrag extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.newlevel, container, false); } } </code></pre> <p>MainActivity.java</p> <pre><code>public class editorActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.editor); // Check that the activity is using the layout version with the fragment_container FrameLayout if(findViewById(R.id.fragment_container) != null) { // if we are being restored from a previous state, then we dont need to do anything and should // return or else we could end up with overlapping fragments. if(savedInstanceState != null) return; // Create an instance of editorFrag editorFrag firstFrag = new editorFrag(); // add fragment to the fragment container layout getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFrag); } } } </code></pre> <p>Answered:</p> <p>Luksprog answered this problem for me below by telling me to check my imports. Eclipse chose to import the SDK version of Fragment instead of the support version that I needed. Thank you for the help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload