Fix Android Fragment Error

Fix Android Fragment ErrorHere I’ll show you how to quickly fix the Android Fragment error that many people are having trouble with. This fix will work with every part of my Android video tutorial.

I have both a video as well as a step-by-step list below on how to fix it. While my current Android tutorial is still very current I’m also planning on making another Java Android tutorial very soon. I just wanted to get this quick fix out as soon as possible.

If you like videos like this, it helps to tell Google Plus with a click here [googleplusone]

Fix Android Fragment Error Step-by-Step

Fix Android Fragment Error

1. Copy everything in res/layout/fragment_main.xml

2. Paste everything from res/layout/fragment_main.xml over everything in 

3. Delete res/layout/fragment_main.xml

4. In delete the following

In onCreate

if (savedInstanceState == null) {
					.add(, new PlaceholderFragment()).commit();


public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {

		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
			return rootView;
5. Comment out all unused imports to make all warnings go away.

5 Responses to “Fix Android Fragment Error”

  1. Sbo says:

    Hi Derek,

    It great that you are continuing with the android tutorials, would you please cover google api like map view, geocoder and maybe some media stuff like placing images from mediastore on map based on their meta data

  2. qua says:

    we dont need to replace the “.. extends ActionBarActivity”
    with “… extends Activity” ?

  3. Brett Schormann says:

    Would like to see a tutorial using the newer implementation of fragments.

Leave a Reply

Your email address will not be published.