我得到2找不到符號錯誤,它似乎不是類路徑的結果。我也有一個問題,讓我的.add方法從listinterface.java代碼在我的pex6.java中工作。我不知道是否因爲即時通訊使用整數類型和添加方法是無效的,但我不知道。我現在已經用java工作了大約6個月,所以我對它仍然很陌生。讓我知道是否有遺漏。有一個找不到符號錯誤,另一個
public interface ListInterface<T>
{
/**
* Should return the number of elements contained within this list:
*/`enter code here`
int size();
/**
* Should return true if this list contains a copy of the given object:
*
* Comparisons should be performed by calling the equals(...) method of
* each element, passing the given object as an argument
*/
boolean contains (T theObject);
/**
* Should remove the first element found within this list that exists as a
* copy of the given object and return true if such an element was found:
*/
boolean remove (T theObject);
/**
* Should return a reference to the first element found within this list
* that exists as a copy of the given object or null if no such element was
* found:
*/
Object get (T element);
/**
* Should return a nicely formatted string representation of this list:
*/
String toString();
/**
* Should print the contents of this list to the screen:
*/
void writeLinkedList();
/**
* Should initialize this list for iteration (use of the getNext() method):
*/
void reset();
/**
* Should return a reference to the element located at the iterator's
* current position and increment the iterator:
*
* If the iterator is currently pointing to the last element in this list,
* the iterator should be reset to point to the first element in this list.
*
* @Preconditions:
* This list is not empty.
* This list has been reset.
* This list has not been modified since the last reset.
*/
T getNext();
/**
* Should insert the given object onto the front of this list:
*/
void add (T theObject);
}
public class PEX6
{
public static void main (String[] theArgs)
{
ListInterface<String> list = new RefList<T>();
for (int i = 1; i <= 20; i++);
{
int Random = ((int) (Math.random() * 4));
list.add(new Integer(Random));
list.writeLinkedList();
}
}
private static int CountValue(ListInterface<T> theList,int theValue)
{
theList.clear();
Integer nFound = 20;
return nFound;
}
}
錯誤:
C:\Users\Linville\Documents\Assignment 6\PEX6.java:16: error: cannot find symbol
private static int CountValue(ListInterface<T> theList,int theValue)
^
symbol: class T
location: class PEX6
C:\Users\Linville\Documents\Assignment 6\PEX6.java:5: error: cannot find symbol
ListInterface<String> list = new RefList<T>();
^
symbol: class T
location: class PEX6
C:\Users\Linville\Documents\Assignment 6\PEX6.java:11: error: method add in interface ListInterface<T> cannot be applied to given types;
list.add(new Integer(Random));
^
required: String
found: Integer
reason: actual argument Integer cannot be converted to String by method invocation conversion
where T is a type-variable:
T extends Object declared in interface ListInterface
3 errors
Tool completed with exit code 1
通過PEX6.java不以任何方式完成的方式,但我想先走,並得到正確的代碼編譯,所以我就不說了當我完成時,最終會有很多錯誤需要解決。
提示:'ListInterface名單=新RefList ();)'應該是'ListInterface 名單=新RefList (;' –
什麼都有您爲PEX6.java編寫了哪些內容? – gparyani
感謝您使用add方法的幫助。現在唯一剩下的就是無法找到符號錯誤。要回答你問qparyani的問題,我已經編寫了pex6類的所有代碼。我沒有完成它,因爲我必須編寫countvalue方法。 – user1881179