Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

intelliJ IDEA: java.lang.ClassNotFoundException

I'm using Intellij IDEA and getting this error:

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: Check this Image

like image 748
raghu Avatar asked Feb 08 '23 18:02

raghu


1 Answers

Exception in thread "main" java.lang.ClassNotFoundException: Main

In the run/debug configuration you have written wrong class name for the Main class field. The name of the class should be the class that has main method to run.

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. 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.

like image 113
Roman C Avatar answered Feb 11 '23 17:02

Roman C