Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {


    }

}
like image 908
mskw Avatar asked Jul 02 '14 13:07

mskw


2 Answers

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.

like image 52
Shawnic Hedgehog Avatar answered Oct 18 '22 20:10

Shawnic Hedgehog


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"
like image 4
mike_m Avatar answered Oct 18 '22 18:10

mike_m