我正在嘗試運行書「Head First Java」中的第一個示例之一;java - 缺少主類
public class MyFirstApp {
public static void main (String[] args){
System.out.println("I Rule!");
System.out.println("The Worlds!");
}
}
「javac的」創建從java文件.class文件 - 但「Java」的抱怨「缺少主類」試圖運行.class文件時(我也嘗試java命令「。 ......」同樣的結果):
C:\>java \hfj\MyFirstApp.class
Exception in thread "main" java.lang.NoClassDefFoundError: \hfj\MyFirstApp/class
Caused by: java.lang.ClassNotFoundException: \hfj\MyFirstApp.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: \hfj\MyFirstApp.class. Program will exit.
我試過在沒有.class擴展名的情況下運行它,但總是以完整路徑作爲參數,而不是從目錄本身。謝謝:) – Gero 2010-02-19 17:43:33