功能我有這個功能收到錯誤:「非靜態方法不能從靜態上下文中引用」同時呼籲從主
private ArrayList<Letters> getLettersInfo(String input)
{
ArrayList<Letters> al = new ArrayList<Letters>();
for (char c : ALPHABET.toCharArray())
{
Letters l = new Letters();
l.setLetter(Character.toString(c));
int count = countOccurrences(input, c);
l.setCount(count);
l.setFrequency(count/28);
al.add(l);
}
return al;
}
然後我嘗試這在我的主:
ArrayList<Letters> al = new ArrayList<Letters>();
al = getLettersInfo(plainText);
for(Letters l : al)
{
System.out.print("Letter: " + l.getLetter() + ", "
+ "Count: " + l.getCount() + ", "
+ "Frequency: " + l.getFrequency());
}
但我得到non static method cannot be referenced from a static context
。我讀了一些關於這個錯誤的東西,但似乎一切都好。任何幫助?
但它不是,因爲你試圖從你的靜態函數調用實例方法。要麼創建一個實例,要麼使該方法成爲靜態的。 –
努力尋找愚蠢,每個人。 –