Error: A JNI error has occurred, please check your installation and try again
1·错误
今天用 Idea 跑main主函数时报如下错误
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632) Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 7 more Process finished with exit code 1
百度了一下基本都是说改Java或者软件配置,这个不排除。
但是!建议先考虑是否是 关键字 原因。
我跑 main 函数的类名是 Util,和 jdk 自带的包名冲突了,导致报错。
换了个类跑 main 函数就没问题了。
2·解决办法:
1.换个类跑 main 函数
2.更改类名(类名尽量区别系统包名)