我寫了一個簡單的包裝程序:如何在java中編譯包?
//A simple package
package MyPack
class Balance
{
String name;
double bal;
Balance(String n, double b)
{
name=n;
bal=b;
}
void show()
{
if(bal<0)
System.out.println("-->");
System.out.println(name+ ": $:" +bal);
}
}
class AccountBalance
{
public static void main(String args[])
{
Balance current[]=new Balance[3];
current[0]=new Balance("A.K.Juwatkar",123.123);
current[1]=new Balance("A.P.Dhoke",345.67);
current[2]=new Balance("Anil Sarang",100.98);
for(int i=0;i<3;i++)
current[i].show();
}
}
我使用Ubuntu 10.04 & 當我把它用
java MyPack.AccountBalance
我收到以下消息編譯:
Exception in thread "main" java.lang.NoClassDefFoundError: MyPack/AccountBalance
Caused by: java.lang.ClassNotFoundException: MyPack.AccountBalance
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: MyPack.AccountBalance. Program will exit.
出了什麼問題?請幫助我。 我已經安裝了openjdk,我是否需要安裝其他的東西? 我使用Ubuntu 10.04,請幫我出
您是否在帳戶餘額中導入了mypack.Balance? –
http://shivasoft.in/blog/java/compile-and-run-java-program-in-package-from-command-line/ – Maddy
http://www.ntu.edu.sg/home/ehchua/編程/ JAVA/J9c_PackageClasspath.html –