知道此处是藏龙卧虎之地,所以想请各位高手帮我看看为何会出现如下异常:
java.lang.ClassNotFoundException: Double
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:164)
        at Stack$StackNode.<init>(Stack.java:53)
        at Stack.<init>(Stack.java:26)
        at Stack.main(Stack.java:140)
异常!StackNode(U, String)的定义中forName方法调用执行时找不到Double类的定义!请
检查调用Stack(U theValue, String nameForU)创建新栈对象时nameForU的取值是否为theV
alue的类型(含子类)!程序执行将被终止!我搞不明白,Double是JAVA支持的类,为何会出现以上异常(即怎么会找不到该类?)。
不知道是不是我的理解有误。请各位指教。代码如下:(我想要实现真正意义上的深拷贝----得到另外一个与之一模一样的栈结点)import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.io.PrintStream;public class Stack<T extends Object & Comparable<T>>
{
public <U extends T> Stack(U newNodeValue, String nameForU)
                                             //创建仅有一个结点的栈,该结点
                                             //值域引用newNodeValue所引用的
                                             //对象
                                             //界面参数简介:
                                             //newNodeValue:栈中唯一一个结点
                                             //  值域所引用的对象
                                             //注:必须引用一个实际存在的对象
                                         //nameForU:类型参数U类型的类名
                                         //注:不能引用空字符串
{
                 //接口参数合法性检验
assert(newNodeValue != null) : "错误!Stack.Stack(U newNodeValue, String nameForU)接口参数newNodeValue必须引用一个实际存在的对象!程序执行将被终止!";
assert(nameForU != null) : "错误!Stack.Stack(U newNodeValue, String nameForU)接口参数nameForU不能引用一个空字符串!程序执行将被终止!";
                 //正常初始化
    StackNode newStackNode = new StackNode(newNodeValue, nameForU);
    if(newStackNode == null)                 //未能成功创建新结点
    {
     return;
    }//if(newStackNode == null)
    this.top = this.bottom = newStackNode;
    this.numStackNode = 1;
}//Stack(T newNodeValue, String)

private class StackNode                      //栈结点
{
public <U extends T> StackNode(U theValue, String nameForU)
                                         //生成一个值域的值为theValue的新
                                         //的栈结点
                                         //接口参数简介:
                                         //theValue:新结点值域的值
                                         //注:必须引用一个实际存在的对象
                                         //nameForU:类型参数U类型的类名
                                         //注:不能引用空字符串,且必须为
                                         //    theValue类型的类名
{
                 //接口参数合法性检验
assert(theValue != null) : "错误!Stack.StackNode.StackNode(U theValue, String nameForU)的接口参数theValue必须引用一个实际存在的对象!程序执行将被终止!";
assert(nameForU != null) : "错误!Stack.StackNode.StackNode(U theValue, String nameForU)的接口参数nameForU必须引用一个非空字符串!程序执行将被终止!";
Class classForU = null;              //类名为nameForU的类对象
try
{
classForU = Class.forName(nameForU);
}//try
catch(ExceptionInInitializerError e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中forName方法调用执行对应构造函数进行初始化失败!请...!程序执行将被终止!");
System.exit(-1);
}//catch(ExceptionInInitializerError)
catch(LinkageError e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中forName方法的调用执行发生连接异常!请...!程序执行将被终止!");
System.exit(-2);
}//catch(LinkageError)
catch(ClassNotFoundException e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中forName方法调用执行时找不到" + nameForU + "类的定义!请检查调用Stack(U theValue, String nameForU)创建新栈对象时nameForU的取值是否为theValue的类型(含子类)!程序执行将被终止!");
System.exit(-3);
}//catch(ClassNotFoundException)
if(classForU.getClass() !=  theValue.getClass())
{
System.out.println("错误!Stack.StackNode.StackNode(U theValue, String nameForU)的接口参数nameForU必须为theValue所在类的类名!无法创建本栈结点!");
return;
}//if(classForU.getClass() !=  theValue.getClass())
                 //正常初始化
try
{
this.value = (T)classForU.getConstructor(classForU).newInstance(theValue);
}//try
catch(ExceptionInInitializerError e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中newInstance方法调用执行时初始化失败!请...!程序执行将被终止!");
System.exit(-1);
}//catch(ExceptionInInitializerError)
catch(NoSuchMethodException e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中getConstructor方法调用执行时找不到对应的构造函数!请...!程序执行将被终止!");
System.exit(-4);
}//catch(NoSuchMethodException)
catch(IllegalAccessException e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中newInstance方法调用执行时无法访问对应的构造函数!请...!程序执行将被终止!");
System.exit(-5);
}//catch(IllegalAccessException)
catch(IllegalArgumentException e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中newInstance方法调用执行时无法找到对应的构造函数!请...!程序执行将被终止!");
System.exit(-6);
}//catch(IllegalArgumentException)
catch(InstantiationException e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中newInstance方法调用执行时发现该类为抽象类!请检查调用Stack(U theValue, String nameForU)创建新栈对象时nameForU的取值是否为theValue的类型(含子类)!程序执行将被终止!");
System.exit(-7);
}//catch(InstantiationException)
catch(InvocationTargetException e)
{
e.printStackTrace(System.err);
System.out.println("异常!StackNode(U, String)的定义中newInstance方法调用执行时所用构造函数抛出异常!请...!程序执行将被终止!");
System.exit(-8);
}//catch(InvocationTargetException)
}//StackNode(U, String)

public String toString()                 //返回值格式:
                                         //  即value.toString()的返回值
                                         //  格式
{
return(this.value.toString());
}//toString()

    private T value = null;                  //结点值域的值
    private StackNode nextNode = null;       //引用与本栈结点紧密相连,但更
                                             //靠近栈底的结点对象
}//class StackNode
int numStackNode = 0;                        //当前栈中结点数量
StackNode top = null;                        //栈顶
StackNode bottom = null;                     //栈底

public static void main(String[] args)       //测试代码
{
Stack<Double> doubleStack1 = null;       //仅有一个结点的栈

doubleStack1 = new Stack<Double>(1.9, new String("Double"));
System.out.println("测试构造函数Stack.Stack(U):");
System.out.printf("浮点数堆栈----栈顶结点的值:%2d栈底结点的值:%2d", doubleStack1.top, doubleStack1.bottom);
System.out.println("栈中结点数量:" + doubleStack1.numStackNode);
System.out.println("正确答案:栈顶,栈底结点的值都为1.9,栈中结点数量为1");
    }//main(String[])
}//class Stack