简体   繁体   English

找不到或加载主类

[英]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. 我从Windows cmd提示符下运行程序。

Program: 程序:

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

Saved the source code as Bla.java . 将源代码保存为Bla.java Compiled the program with javac Bla.java --> Bla.class created. javac编译的程序Bla.java - > Bla.class创建。 Tried to run the program with java Bla.class I get the error : "Could not find or load main class Bla.class" 试图使用Java Bla.class运行程序,但出现错误 :“找不到或加载主类Bla.class”

I am not a complete newbie with java 我不是Java的完全新手

1. I have configured my path and my classpath variable (Exact values below). 1.我已经配置了路径和classpath变量(下面的确切值)。 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 路径: %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 2.我的程序不属于任何程序包,也不调用任何程序包

I call everything from my command line. 我从命令行调用所有内容。 I tried uninstalling and reinstalling java developer kit.Every time I get the same error. 我尝试卸载并重新安装Java Developer Kit。每次遇到相同的错误。 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. 这不是我第一次安装Java或在Java中运行程序,但我已经很长时间没有写东西了。 What am I doing wrong? 我究竟做错了什么?

Thanks 谢谢

Assuming your working directory containes Bla.class, and your CLASSPATH contains a "." 假设您的工作目录包含Bla.class,而CLASSPATH包含“。”。 (among others), java should be able to find it. (以及其他),java应该能够找到它。

However, you should call it without ".class", like this: java Bla . 但是,您应该不带“ .class”来调用它,就像这样: java Bla Otherwise, java will think you want to call a class called "class" in package "Bla". 否则,java会认为您要在包“ Bla”中调用一个名为“ class”的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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