出现如下错误是何原因?
package Test;
//Demonstrate static variables,methods,and blocks.
class UseStatic
{
static int a = 3;
static int b;
static void meth(int x)
{
System.out.println("x = " + x);
System.out.println("a = " + a);
System.out.println("b = " + b);
}
static
{
System.out.println("Static block initialized.");
b = a * 4;
}
public static void main(String args[])
{
meth(42);
}
}
Caused by:
java.lang.ClassNotFoundException: Test.Test5
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Exception in thread "main"
------解决方案--------------------我猜楼主点击的是eclipse上面的run工具栏执行的吧,如果你用的是eclipse,在这个类的编辑界面,右击鼠标,Run As-->Java Application
------解决方案--------------------楼上正解,如果右键找不到Run As-->Java Application,请改成public class UseStatic