Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Niraj Chaudhary
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
RyanYang Yu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garg Unzola's method is working.
I have same problem. It because I uninstalled my old version jre. So I download an new jre. And set the preference to the new one. The problem solved
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic