我已经从网上下载了一个简单的 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 SimpleArrayListExample.java
现在我正在尝试使用
java -classpath . ArrayList.SimpleArrayListExample.java
线程“主”java.lang.NoClassDefFoundError 中的异常
我谷歌发现我必须指定 -classpath 。
http://www.tech-recipes.com/rx/826/java-exception-in-thread-main-javalangnoclassdeffounderror/ 似乎无法解决问题。