我已經下載從net.I我試圖編譯下面運行時錯誤:運行Java類文件
package ArrayList;
import java.util.ArrayList;
public class SimpleArrayListExample {
public static void main(String[] args) {
//create an ArrayList object
ArrayList<String> arrayList = new ArrayList<String>();
/*
Add elements to Arraylist using
boolean add(Object o) method. It returns true as a general behavior
of Collection.add method. The specified object is appended at the end
of the ArrayList.
*/
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
/*
Use get method of Java ArrayList class to display elements of ArrayList.
Object get(int index) returns and element at the specified index in
the ArrayList
*/
System.out.println("Getting elements of ArrayList");
System.out.println(arrayList.get(0));
System.out.println(arrayList.get(1));
System.out.println(arrayList.get(2));
}
}
給出的代碼,我編輯的程序,按您的建議,一個簡單的Java例子,我可以編譯我得到了類文件。
java SimpleArrayListExample.java
現在我想執行使用
java -classpath . ArrayList.SimpleArrayListExample.java
異常文件中的線程「主要」 java.lang.NoClassDefFoundError
我谷歌和發現,我必須指定-classpath 。
http://www.tech-recipes.com/rx/826/java-exception-in-thread-main-javalangnoclassdeffounderror/似乎沒有解決問題。
你嘗試編譯器提出什麼「重新編譯-Xlint:取消選中」? –
(-1)*請在提問前搜索錯誤信息* - 嘗試'arraylist unchecked或unsafe operation' – 2013-01-23 21:42:15
http://stackoverflow.com/questions/12947806/unsafe-or-unchecked-operations-for-arraylist ,http://stackoverflow.com/questions/197986/what-causes-javac-to-issue-the-uses-unchecked-or-unsafe-operations-warning – 2013-01-23 21:43:46