开发者

could not find the main class

I'm using the JDK 3.1. I am using XML Publisher. I'm getting this error:

Could not find the main class. Program will exit.

After I click on "OK", I get

Java execu开发者_如何学运维tion failed. Please check the Java Option in the option dialog


Sounds like you're trying to execute .jar file and there's no Main-Class entry in the manifest file. Other than that obvious point, your question does not give much information for assistance.


Your question is tricky to understand, but I'm guessing that you haven't actually compiled your Java code, or your compiled code isn't on the classpath.

When I try and execute a non-existent class (this would work if there was a MyClass.class on the classpath with a main() method):

paul@paul-laptop:~$ java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
Caused by: java.lang.ClassNotFoundException: MyClass
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: MyClass.  Program will exit.

Is that what you're seeing? If so:

  • compile your class with javac if you haven't done so
  • check that your classpath includes the location of the class

(You can specify the classpath explicitly when you execute the java program using -classpath, check the documentation for details.)


I include this answer as someone who has made an error someone consuming java rather than programming in it would make:

On the command line when executing a JAR file, be sure your line reads
java -jar whatever.jar

instead of

java whatever.jar

Without the -jar you sometimes get the "Could not find the main class" error.


Here are some good answers What does "Could not find or load main class" mean?

But, I will share one possibility I had. I used the JDK1.7 to compile my code and run the jar package using the JDK1.6, the error is:

Could not find the main class. Program will exit.

So, check if the JDK version you used to run your code is lower than that used to compile your code.


Check this website: "Could not find main class" error when previewing BI Publisher for Word. It directly references Java issues with Oracle BI Publisher Plugins for Word.

It basically says that you need to set your Java Home by going to Options in the BI Publisher Tab in the MS Office Ribbon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜