0
我有兩個類。 一個是短語類,找不到符號 - 方法(通用方法)
import java.util.List;
import java.util.ArrayList;
@SuppressWarnings("unchecked")
public class Phrase
{
List<String> papers = new ArrayList();
String name = "";
boolean multiple = false;
public Phrase(String name, List list)
{
this.name = name;
this.papers = list;
if(list.size() > 1)
{
multiple = true;
}
}
public Phrase(String name, String pName)
{
this.name = name;
this.papers.add(pName);
multiple = false;
}
public void addPaper(String paper)
{
papers.add(paper);
multiple = true;
}
public String getPhrase()
{
return name;
}
public List<String> getPapers()
{
return papers;
}
}
另一個是KeyedLinkedList。
public class KeyedLinkedList<K,Phrase>
{
private KeyNode first;
private int size;
private class KeyNode
{
K key;
Phrase value;
KeyNode previous;
KeyNode next;
public KeyNode(K key, Phrase value, KeyNode previous, KeyNode next)
{
this.key = key;
this.value = value;
this.previous = previous;
this.next = next;
}
}
public int size()
{
return size;
}
public boolean put(K key, Phrase val)
{
if(isEmpty())
{
first = new KeyNode(key, val, null, null);
first.next = first;
first.previous = first;
size++;
return true;
}
KeyNode temp = first;
if(temp.key.equals(key))
{
//****ERROR LOCATION****//
temp.value.addPaper(val.getPapers().get(0));
//****ERROR LOCATION****//
if(temp.value.getPapers().size() < 3)
return false;
return true;
}
temp = temp.next;
while(temp != first)
{
if(temp.key.equals(key))
{
temp.value.addPaper(val.getPapers().get(0));
if(temp.value.getPapers().size() < 3)
return false;
return true;
}
temp = temp.next;
}
temp.previous.next = new KeyNode(key, val, temp.previous.next, first);
first.previous = temp.previous.next;
size++;
return true;
}
}
當我編譯這個我得到的錯誤:「找不到符號 - 方法getPapers()」
我明明有getPapers()方法在我的短語類和Val中的參數是短語對象。我想知道我需要做什麼來解決這個問題。該錯誤發生在put方法的一半。
您能指出我們在代碼中確切的區域,它抱怨錯誤嗎?其實,我認爲你需要提供KeyNode類的代碼 – pczeus