Could not find or load main class

后端 未结 16 1052
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 20:27

I have Windows 7, installed jdk1.7.0 and its supporting jre7.
My problem is compilation part works perfectly, but while running the Java program I get this error saying:

相关标签:
16条回答
  • 2020-11-27 20:42

    Here is my working env path variables after much troubleshooting

    CLASSPATH

    .;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;C:\Program Files (x86)\Java\jdk1.6.0_27\bin

    PATH <---sometimes this PATH fills up with too many paths and you can't add a path(which was my case!)

    bunchofpaths;C:\Program Files (x86)\Java\jdk1.6.0_27\bin

    Additionally, when you try to use the cmd to execute the file...make sure your in the local directory as the file your trying to execute (which you did.)

    Just a little checklist for people that have this problem still.

    0 讨论(0)
  • 2020-11-27 20:45

    I faced a similar problem in Eclipse. Whenever I clicked on the Run button it gave me the message, "Error: Could not find or load main class". But when I right click on the java file in the project explorer and Run As Java configuration, it works perfectly.

    I think this is because it tries by default to run it in some other configuration which causes problems.

    Hope this answer helps some.

    0 讨论(0)
  • 2020-11-27 20:45

    i had

    ':'

    in my project name e.g 'HKUSTx:part-2' renaming it 'HKUSTx-part-2' worked for me

    0 讨论(0)
  • 2020-11-27 20:47

    First, put your file *.class (e.g Hello.class) into 1 folder (e.g C:\java). Then you try command and type cd /d C:\java. Now you can type "java Hello" !

    0 讨论(0)
  • 2020-11-27 20:48

    Try:

    java -cp . p1
    

    This worked for me when I had the same problem, using Fedora (linux)

    0 讨论(0)
  • 2020-11-27 20:52

    I had almost the same problem, but with the following variation:

    1. I've imported a ready-to-use maven project into Eclipse IDE from PC1 (project was working there perfectly) to another PC2
    2. when was trying to run the project on PC 2 got the same error "Could not find or load main class"
    3. I've checked PATH variable (it had many values in my case) and added JAVA_HOME variable (in my case it was JAVA_HOME = C:\Program Files\Java\jdk1.7.0_03) After restarting Ecplise it still didn't work
    4. I've tried to run simple HelloWorld.java on PC2 (in another project) - it worked
    5. So I've added HelloWorld class to the imported recently project, executed it there and - huh - my main class in that project started to run normally also.

    That's quite odd behavour, I cannot completely understand it. Hope It'll help somebody. too.

    0 讨论(0)
提交回复
热议问题