1

I am trying to inflate one of my fragments. However, the fragment does not show up in the autosuggest. So I manually entered the name of the fragment. By doing that the fragment name was showing in red text color and also red squiggly lines showing below all of the class names. However, when I run the application, it runs perfectly without any errors.

I have three fragments: fragment_dynamic_android.xml, fragment_dynamic_windows.xml and fragment_dynamic_ios.xml.

I can able to inflate the fragment_dynamic_android.xml in AndroidFragment.java class on onCreateView method.

But when I try to inflate the fragment_dynamic_windows.xml on WindowsFragment.java's onCreateView method.

The red textcolor is showing on

View rootView = inflater.inflate(R.layout.fragment_dynamic_windows, container, false);

The applications run without any error.

package app.tab.simple.fragmenttut;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class WindowsFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_dynamic_windows, container, false);
        return rootView;
    }
}
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
Phil
  • 97
  • 8

1 Answers1

1

After some frustration, Switched off the pc and went to do some stuff. Came again and opened the project, the error was gone. Not sure why android studio behaved like that.

Phil
  • 97
  • 8
  • its because when you again started your android studio , your project got Rebuild , whenever you face this kind of problem in future , try to clean | rebuild your project , hopefully that will solve your problem . – Sachin Rajput Mar 22 '19 at 16:57
  • Cleaning and rebuilding didn't work for me. But restarting Android Studio was enough. – Jack' Aug 05 '20 at 09:41