[英]intelliJ IDEA: java.lang.ClassNotFoundException
I'm using Intellij IDEA and getting this error: 我正在使用Intellij IDEA并收到此错误:
Exception in thread "main" java.lang.ClassNotFoundException: siimport.Pres at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122) Process finished with exit code 1
My code is, 我的代码是,
package si;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Pres
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("kk.data"));
BufferedWriter bw = new BufferedWriter(new FileWriter("samlog.csv"));
String line;
while((line = br.readLine()) != null)
{
String[] values =line.split(" ", -1);
bw.write(values[0] + "," + values[3] + "," + values[5] + "\", "+values[6]+ "," + values[8] + "\n");
}
br.close();
bw.close();
}
}
What could be the problem which is resulting this error and how can I resolve? 可能导致此错误的问题是什么?如何解决?
I also made this screenshot: 我也做了这个截图:
Exception in thread "main" java.lang.ClassNotFoundException: Main
In the run/debug configuration you have written wrong class name for the Main class field. 在运行/调试配置中,您为Main类字段写了错误的类名。 The name of the class should be the class that has main
method to run. 类的名称应该是具有要运行的main
方法的类。
This error could also happen if you didn't create or didn't select run/debug configuration for the class. 如果您没有为类创建或未选择运行/调试配置,也可能发生此错误。 To create it use Edit Configurations -> Add new under application tree item or from the editor press Alt + hift + F10 and choose your file to run. 要创建它,请使用编辑配置 - >在应用程序树项下添加新项或从编辑器按Alt + hift + F10并选择要运行的文件。 The configuration will be added automatically. 配置将自动添加。 To select current run/debug configuration use dropdown from the toolbar. 要选择当前运行/调试配置,请使用工具栏中的下拉列表。
Usually I prefer to choose from menu Run -> Run , but as @Bajal mentioned in the comment, you can right-click on the file from the Project Structure and choose Run from the popup menu or press Ctrl + Shift + F10 . 通常我更喜欢从菜单Run - > Run中选择 ,但是作为评论中提到的@Bajal,您可以右键单击Project Structure中的文件,然后从弹出菜单中选择Run或按Ctrl + Shift + F10 。
Just as an aside, I was having this problem and resolved it as the run configuration was using "Use Classpath of module" ProjectName 顺便说一下,我遇到了这个问题并解决了它,因为运行配置正在使用“使用模块的类路径”ProjectName
i changed it from that to 我把它改成了
"Use Classpath of module" ProjectName_main “使用模块的类路径”ProjectName_main
and that made it work - I personally do not like how they have added these sub modules but i guess if you are using stuff like gradle/maven you will have to put up with it in Intellij. 这使它工作 - 我个人不喜欢他们如何添加这些子模块,但我想如果你使用像gradle / maven这样的东西你将不得不忍受它在Intellij。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.