This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes General Computing and the fly likes Error: Could not find the main class. Program will exit. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Error: Could not find the main class. Program will exit." Watch "Error: Could not find the main class. Program will exit." New topic
Author

Error: Could not find the main class. Program will exit.

Niraj Chaudhary
Greenhorn

Joined: Feb 03, 2011
Posts: 5
Hi,

I have a java application that is started from an executable. When I try to run that, This error pops up "Title: Java Virtual Machine Launcher" saying "Could not find the main class. Program will exit."

This error is coming when the application is tried to run on some machines (that's what I think), and not for all the users. Following are the steps that have been suggested, but the error still persists:
1.Uninstall any older/ multiple versions of java from the Windows machine and keep only the latest one.
2.Point the environment variable "CLASSPATH" to the directory where "java" is present, and also to the main class of my application.
3.Try installing the tool on a different machine (in the same network domain).

I have seen many posts in this and other forums on this topic, and the solutions suggested above have been taken from them, but the solution for my problem here is not there. It may be a trivial mistake or something else, but please help me out, as I am only a beginner in trying to solve such problems.

Also, if you can please tell me how do I get this error, on my machine, that would be great? Something to understand the steps causing the problem. I don't get the error pop-up on my system.

Thank you so very much in advance!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
Welcome to the Ranch

Any suggestions about setting a CLASSPATH are likely to be unhelpful. In fact a system CLASSPATH can do more harm than good. The sort of error you quote suggests you have nothing wrong with the Java™ installation, but there is a problem with your own file.

You are not clear about what you are running. Are you running a .jar or a .exe? If a .jar, what is in its manifest file? Please print that out. What is the fully-qualified name of the class with the main mathod in?
Niraj Chaudhary
Greenhorn

Joined: Feb 03, 2011
Posts: 5
I am trying to run a ".exe". And the main class called from the exe is present in a .zip file. The contents of the zip are shown below. The main class is "pkgLib.ProgABDriver".

...
pkgLib/
pkgLib/ReadExRule.class
pkgLib/checkLic.class
pkgLib/envVarTokenizer.class
pkgLib/LOC.class
pkgLib/clearHistory.class
pkgLib/StatusListener.class
pkgLib/repErr.class
pkgLib/ProgABDriver$1.class
pkgLib/RTInit.class
pkgLib/ProgABDriver.class
pkgLib/RulesOrder.class
pkgLib/writeBean.class
....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
Don't know. There ought to be some way to mark which is the class with the main() method you want to run; in a .jar that is in the manifest file. You appear not to have a manifest file in that .exe.

Don't know, but this isn't a "beginning Java™" question. I shall move this discussion; not sure whether to Java™ in General, or General Computing, but I prefer "General Computing".
Maria Vela
Greenhorn

Joined: Feb 02, 2012
Posts: 2
Solution: Look in windows the file java.exe. It probably will be more than one file.

Open the .bat file that run your aplication and look for a java_path. Something like that:

set JAVA_PATH=c:\Program Files\Java\jre1.6.0_07


It must be the same that java.exe is installed in.
Maybe its empty or maybe it´s a wrong path and so on, the application cannot find java class.

When the application was installed, looked for java. exe. When more that one files exists, the application is lost and do ¿?
but sometimes it´s necesary more than one java file.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
Wlecome to the Ranch

Doesn’t the path entry end in “bin”, or is there a second entry with %JAVA_PATH%\bin in?
Maria Vela
Greenhorn

Joined: Feb 02, 2012
Posts: 2
Thanks and hello.

You´re right. In my case, three posible paths:
c:\windows\system32
c:\archivosdeprograma\Java\jre6\bin
c:\archivosdeprograma\Oracle\JInitiator 1.3.1.13\bin

but it depends on each pc. So a search is necesary. I´ve just written an example. I filled the java-path with second one and it went OK.

I´ve been googling a lot just for solve this problem, and it´s more usual than I though, but no exact solutions are related, just propositions and opinions.

Garg Unzola
Greenhorn

Joined: Jan 18, 2013
Posts: 1
I recently encountered the same error while using Eclipse. Turns out I changed the default version of the JRE instead of just the version for a specific project. This leads me to believe your error may be as a result of the Java version on some machines that are incompatible with the compiled version of the .jar file.

In Eclipse, I could resolve this issue by changing the JRE version referred in my runtime libraries. Not sure how you'd fix this for a standalone program, but hope this helped.
 
jQuery in Action, 2nd edition
 
subject: Error: Could not find the main class. Program will exit.
 
Similar Threads
Problem with WLI 2.1 SP1 Startup
Java Virtual Machine troubleshooting
xxxx.jar seen as xxxx.zip on desktop and won't run
Problem when make .jar file from my java applet program!!!
Must or must not have main...