mskw
mskw

Reputation: 10318

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


    }

}

Upvotes: 5

Views: 12814

Answers (3)

TKhan
TKhan

Reputation: 1

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

Upvotes: 0

Shawnic Hedgehog
Shawnic Hedgehog

Reputation: 2373

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.

Upvotes: 6

mike_m
mike_m

Reputation: 1546

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"

Upvotes: 4

Related Questions