4

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

6
  • This code seems not to throw such exception. You are running this code using another class? Because your error log says com.intellij.rt.execution.application.AppMain.main(AppMain.java:122) and it seems there is something wrong with your compilation or building phase and it cannot find your compiled class to run. Commented Feb 14, 2016 at 12:11
  • 1
    How can I sove this problem @Staefi Commented Feb 14, 2016 at 12:12
  • Does your real code has such package declaration with syntax error: papackage si; ? Commented Feb 14, 2016 at 12:14
  • There is no problem with that. Commented Feb 14, 2016 at 12:17
  • so please edit you question's code to correct papackage si; to package si; Commented Feb 14, 2016 at 12:19

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

9 Comments

I saved file as Pres.java but on pressing your suggested keys it is showing Main and why it is not showing Pres
I just created the file and running as it is. But, Where does the problem persisting as you said first.
Have you tried right clicking on the file (either in project view, or in the editor window) and choosing run?
what is the folder name where the file is?
The folder name is src
|
4

Just as an aside, I was having this problem and resolved it as the run configuration was using "Use Classpath of module" ProjectName

i changed it from that to

"Use Classpath of module" 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.