Can't resolve placeholderfragment placeholder error

I am really stuck with this error (below):

     @Override
     protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_vehiclerecall);

      if (savedInstanceState == null) {
          getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

      

I have bound the container to the XML layout correctly (below):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    tools:context="com.customerautomotivenetwork.VehicleRecall"/>

      

But I keep getting the error, cannot resolve method for PlacehlderFragment, any idea what I am doing wrong?

+3


source to share


2 answers


  • You are probably using the wrong version Fragment

In your file, PlaceholderFragment.java

first make sure you expand Fragment

:

public class PlaceholderFragment extends Fragment { //...

      

Then check the import at the beginning of this file. There should be a line:



import android.app.Fragment;

      

and NOT the line:

import android.support.v4.app.Fragment;

      

Try not to mix "normal" and "v4" snippets, they have the same name and do the same thing, but they are actually different classes.

+3


source


I had to import android.support.v4.app.Fragment file to fix this issue.

In my case, I used minSdkVersion 8 and I created Activity java class> Package> Acitivity> BlankActivity. This generated activity class had a public static inner class that PlaceholderFragment extends the fragment. This inner class was used in onCreate () in



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_message);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
    }
}

      

+1


source







All Articles