我用静态方法创建了一个类,我正在尝试访问AllLanguages数组中的一个元素
public final class AllLanguages {
private static Language[] mLanguages;
private AllLanguages(Language[] languages) {
mLanguages = new Language[]
{
new Language(R.drawable.united_kingdom, "English", "en"),
new Language(R.drawable.france, "French", "fr"),
new Language(R.drawable.israel, "Hebrew", "he"),
new Language(R.drawable.germany, "German", "de")
};
}
public static Language[] getLanguages() {
return mLanguages;
}
public static void setLanguages(Language[] mLanguages) {
AllLanguages.mLanguages = mLanguages;
}
public Language getLanguage(int position) {
return AllLanguages[position];
}
}
在最后一个方法(getLanguage)中,我遇到了以下编译器错误“Expression Expected”。有什么想法吗?
答案 0 :(得分:1)
AllLanguages
是一个不是数组的类,因此AllLanguages[position]
是无效的语法。
您需要更改
public Language getLanguage(int position) {
return AllLanguages[position];
}
到
public Language getLanguage(int position) {
return mLanguages[position];
}