java.lang.ClassNotFoundException程序是這樣的放在c12包下
package c12;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2007/6/26
* Time: 下午 09:17:09
* To change this template use File | Settings | File Templates.
*/
class Candy{
static {
System.out.println( "Loading Candy ");
}
}
class Gum{
static {
System.out.println( "Loading Gum ");
}
}
class Cookie{
static {
System.out.println( "Loading Cookie ");
}
}
public class SweetShop {
public static void main(String[] args) {
System.out.println( "inside main ");
new Candy();
System.out.println( "After creating Candy ");
try {
//Class.forName( "c12\\Gum ");
Class.forName( "Gum ");
} catch (
ClassNotFoundException e) {
e.printStackTrace(
System.err);
}
System.out.println( "After Class.forName(\ "Gum\ ") ");
new Cookie();
System.out.println( "After Creating Cookie ");
}
}
知道是 Class.forName( "Gum ");
這句有問題,不清楚應該如何修改,先寫寫了.
------解决方案--------------------c12.Gum
------解决方案--------------------顾名思义,类的路径嘛,一定是类的路径不对了,要写全的
------解决方案--------------------new FileInputStream( "c11.Redirecting.java ")
流嘛,跟package无关,跟directory有关,用c11\\xxxxx