[Solved] Cannot resolve symbol for Fragments

How come I’m getting this error when I try to declare a Fragment in XML?

<fragment android:name="com.example.news.ArticleListFragment"
          android:id="@+id/list"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:layout_height="match_parent" />

“Cannot resolve symbol: ArticleListFragment”??

Code file name ArticleListFragment.java

package com.example.myapp5;

import android.app.Fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.View;

public class ArticleListFragment extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {


    }

}
Enquirer: mskw

||

Solution #1:

How the Fragment should be set up

I don’t know if this completely answers your question, but it sounds like something just isn’t set up properly. I have included an example that should illustrate what your File Explorer should look like given you are running Android Studio (It will still look similar to this in Eclipse).

Now, you need to make sure everything in android:name looks right here, but for your package.

Respondent: mskw

Solution #2:

You use com.example.news.ArticleListFragment as fully qualified class name, but the real name of your class is com.example.myapp5.ArticleListFragment, because you have created it in different package than the tutorial.

So you should use

android:name="com.example.myapp5.ArticleListFragment"
Respondent: Shawnic Hedgehog

Solution #3:

You need to first import your fragment in the java file.

Respondent: mike_m

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published. Required fields are marked *

New ride at Perth's Adventure World a ‘swing on steroids’ - Australasian Leisure Management npp pharma the truth about anabolic steroid drugs and professional sports