编译没问题,但运行时出错,以下为错误:Exceptioninthread"main"java.lang.NoClassDefFoundError:MainCausedby:java.lang.ClassNotFoundException:Mainatjava.net.URLClassLoader$1....
编译没问题,但运行时出错,以下为错误:
Exception in thread "main" java.lang.NoClassDefFoundError: Main
Caused by: java.lang.ClassNotFoundException: Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Main. Program will exit.
代码如下:
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int n,i;
n = s.nextInt();
String[] str = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
Map m = new HashMap();
for (i = 0; i < str.length; i++) {
m.put(i, str[i]);
}
for(i = 0;i < n;i++){
useKeySet(m);
}
}
public static void useKeySet(Map m) {
Set s = m.keySet();
Iterator it = s.iterator();
int Key;
String value;
while (it.hasNext()) {
Key = (Integer) it.next();
value = (String) m.get(Key);
if(Key > 12 || Key < 1)
System.out.println("Invalid");
else
System.out.println(value);
}
}
}
展开