Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBenjamin Earle
6,204 PointsError with placeholderFragment, AndroidStudio
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(position + 1);
}
In this part (in the video it shows a dummy fragment) I get an error for the PlaceholderFragment object, it shows that it "Cannot resolve symbol". If I use the quick fix, theres another error where it doesen't return what getItem needs.
1 Answer
Tyrel Hiebert
14,739 PointsI struggled with this for a few hours. Finally, Ben's answer here really helped me.
Make sure in your MainActivity.java that your imports for Fragment, FragmentManager and FragmentPagerAdapter are referencing the v4 support library, like this
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
Instead of any of them being
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentPagerAdapter;
In the notes for this video, it tells you to update the FragmentActivity import, but not the others.
You may not need FragmentManager as it is grey (unused) in my project at this stage, but I left it there anyway as I am just glad that my app will run now.
I hope this helps. I was stuck with this same problem and this seemed to do the trick!
Tyrel Hiebert
14,739 PointsTyrel Hiebert
14,739 PointsOh I forgot this.
Use the quickfix for the PlaceholderFragment in SectionsPagerAdapter.java as well. Make it reference the MainActivity like this
Do this as well as alter the imports in MainActivity.java