我有这个课:
public class SayingsHolder extends Application{
ArrayList<String> SayingsList = new ArrayList<String>(){{
SayingsList.add("1");
SayingsList.add("2");
}};
public ArrayList<String> getSayingsList() {
return SayingsList;
}
}
现在,我尝试通过以下方式在活动的
ScreenSlidePagerAdapter
中调用它:private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
String[] displayText;
final SayingsHolder holder = (SayingsHolder).getApplication();
String names[] = {"1","2","3"};
public ScreenSlidePagerAdapter(FragmentManager fm,String[] displayText) {
super(fm);
this.displayText=displayText;
}
@Override
public Fragment getItem(int position) {
System.out.println(position);
ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
fragment.setText(names[position]);
return fragment;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
但这给了我这个错误:
SayingsHolder cannot be resolved to a variable
我在这里想念什么?我知道我指的是错误的课堂,但是我找不到解决它的方法。有人可以给我一个小提示吗?
最佳答案
尝试这个
final SayingsHolder holder = (SayingsHolder).getApplication();
至
final SayingsHolder holder = (SayingsHolder)getApplication();