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 trialzacharygassem
3,697 PointsSectionsPagerAdapter.java error in Android Studio
I have made all the changes in the Teacher's Notes but I still get an error in SectionsPagerAdapter.java. Here is the code in the file:
package com.example.zacharygassem.blinker;
/**
* Created by Zachary Gassem on 27/09/2014.
*/
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.content.Context;
import java.util.Locale;
/**
* A {@link android.support.v13.app.FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
protected Context mContext;
public SectionsPagerAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
@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 MainActivity.PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return mContext.getString(R.string.title_section1).toUpperCase(l);
case 1:
return mContext.getString(R.string.title_section2).toUpperCase(l);
}
return null;
}
}
```Android
4 Answers
zacharygassem
3,697 PointsNever mind I solved it
Darrius Taylor
1,934 PointsWhat is your error or what line is the error on?
zacharygassem
3,697 PointsI get an error on line 31 and it says "Incompatible types: required: android.support.v4.app.Fragment found: mypackagename.PlaceholderFragment"
zacharygassem
3,697 PointsI get an error on line 31 and it says "Incompatible types: required: android.support.v4.app.Fragment found: mypackagename.PlaceholderFragment"
Jaroslav Vankat
12,054 PointsJaroslav Vankat
12,054 PointsHow did you solve this? Edit: Nevermind I solved it (for other users - the problem was the library in MainActivity, you need to change this line
import android.support.v4.app.Fragment;
to
import android.support.v4.app.Fragment;
Sripathi Balasubrahmanyam
499 PointsSripathi Balasubrahmanyam
499 PointsThank you so much!
Sripathi Balasubrahmanyam
499 PointsSripathi Balasubrahmanyam
499 PointsThank you so much!