简体   繁体   中英

Could not find or load main class

Since 2 days now I am trying to run the simplest program and I can't. I run my programs from Windows cmd prompt.

Program:

 public class Bla {
        public static void main(String [] args) {
            System.out.println("works");
        }
    }

Saved the source code as Bla.java . Compiled the program with javac Bla.java --> Bla.class created. Tried to run the program with java Bla.class I get the error : "Could not find or load main class Bla.class"

I am not a complete newbie with java

1. I have configured my path and my classpath variable (Exact values below). Path: %SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\system32\\wbem;C:\\Python27;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0;C:\\Program Files (x86)\\Skype\\Phone;C:\\mysql\\bin;C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI\\wbin;C:\\Program Files\\Java\\jdk1.8.0_144\\bin

CLASSPATH: .;C:\\Program Files\\Java\\jre1.8.0_144\\lib;

2. my program doesn't belong to any package and doesn't call any package

I call everything from my command line. I tried uninstalling and reinstalling java developer kit.Every time I get the same error. This is not the first time I have installed java or run a program in java but I haven't written something in a long time. What am I doing wrong?

Thanks

Assuming your working directory containes Bla.class, and your CLASSPATH contains a "." (among others), java should be able to find it.

However, you should call it without ".class", like this: java Bla . Otherwise, java will think you want to call a class called "class" in package "Bla".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM