Could not find or load main class

后端 未结 16 1071
隐瞒了意图╮
隐瞒了意图╮ 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:33

    Simple way to compile and execute java file.(HelloWorld.java doesn't includes any package)

    set path="C:\Program Files (x86)\Java\jdk1.7.0_45\bin"
    javac "HelloWorld.java"
    java -cp . HelloWorld
    pause
    
    0 讨论(0)
  • 2020-11-27 20:33

    I've had similar problems. If you work with Eclipse, you need to go to the folder where you have your src/ folder... If you used a package - then you use

    javac -cp . packageName/className
    

    which means if you've had a package named def and main class with name TextFrame.java you'd write

    javac -cp . def/TextFrame
    

    omitting the trailing .java extension, and then you run it with the

    java def/TextFrame 
    

    and if you have have arguments, then you need to supply it with arguments corresponding to your program. I hope this helps a bit.

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

    Sometimes what might be causing the issue has nothing to do with the main class. I had to find this out the hard way, it was a referenced library that I moved and it gave me the:

    Could not find or load main class xxx Linux

    I just delete that reference and added again and it worked fine again.

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

    You can use NetBeans IDE which is free to download and use "Open Source". You can even do other programming language in this IDE. The latest of which it supports HTML5. This makes your programming easier. If you're not familiar with it choose a book that is NetBeans integrated like Sams Teach Yourself Java in 24 Hours

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

    javac should know where to search for classes. Try this:

    javac -cp . p1.java
    

    You shouldn't need to specify classpath. Are you sure the file p1.java exists?

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

    I was having a similar issue with my very first java program.

    I was issuing this command

    java HelloWorld.class
    

    Which resulted in the same error.

    Turns out you need to exclude the .class

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