When executing "java" command in CMD, it is not possible to locate or load the main class

4

After you run the javac command normally and create the .class file, I try to execute the command java plus it gives this problem of not being able to locate nor load the main class.

I think it might be a mess on the environment variables because I'm starting now to learn programming and really do not understand much about such variables.

Anyway, I used this "step-by-step" in the link below to configure system variables:

link

I used only the commands javac and java in cmd , apart from being located in the directories.

Using this code below, just after the java command to run the program, it occurs. Error: The main CPrincipal class could not be located or loaded.

import javax.swing.JFrame;

public class CPrincipal {

    public static void main (String args[]){

        JFrame janela = new JFrame ();

        janela.setSize(500,300);
        janela.setVisible(true);
    }


}
    
asked by anonymous 10.02.2015 / 16:27

2 answers

5

In the directory where you compiled the file with javac

javac CPrincipal.java

CPrincipal.class will appear

In the same directory, type

java CPrincipal

The JFrame screen should appear normally.

    
12.02.2015 / 19:44
2

You probably did the same nonsense I did when creating the environment variables.

The variable ClassPath must have a .; before the assigned path.

Mine looks like this: .;C:\Program Files\Java\jdk1.8.0_40\lib

    
06.04.2015 / 18:06