9 Replies - 5117 Views - Last Post: 24 October 2011 - 02:26 AM Rate Topic: -----

#1 AVReidy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

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

Posted 21 October 2011 - 09:44 PM

So tonight I decided to brush up on Swing by making a little calculator. I wrote it in Eclipse, and it works fine. I then copied the source code and put it in my regular Java directory where I compiled everything, made a manifest file, and created a JAR file. The weird thing is, my JAR file executes on my computer, but nowhere else. It's just a basic swing GUI; it doesn't use the very latest Java update or anything. So I've tried it on 3 different computers other than the one I created it on, and it doesn't work on any of them. I also tried creating a JAR file from inside Eclipse, and it didn't work either.

My program uses inner classes, and I think this might require that I use packages of some sort to make the JAR file. That's my best guess on how to solve this. As for the reason that it works fine on my PC? I have no idea and I don't really care as long as I can figure out how to make a JAR file that will work on different computers.

I don't know a thing about packages, but I have a suspicion that the absence of them is what is causing my problems.

I'd really appreciate some help on this. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Could not find the main class: CalcMain. Program will exit.

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Could not find the main class: CalcMain. Program will exit.

Posted 21 October 2011 - 09:55 PM

Nothing to do with package, don't search that way

But we will need more details
Show us the output of

> jar tf your.jar

and the content of yourmanifest.mf file
Does it have a blank empty line at the end ?
There is a bug in jar or manifest... a manifest file should end with an empty line
Was This Post Helpful? 0
  • +
  • -

#3 AVReidy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 06:45 AM

Yes, that was a problem at first, but I've gone through the process of compiling from my single .java file which gives me about 5 .class files because I have inner classes for event handling. I compiled these with a manifest.txt, and I accidentally only pressed enter once, but I fixed this and remade the manifest a number of times. It still doesn't work.

What would be the reason for it running fine on my computer but nowhere else?

Should I be including the inner class files when I create my JAR or should I just use my single class that contains them? I've been making the JAR with both the 5 inner class files and my main class.

Here's what my manifest looks like:
Main-Class: CalcMain

With the correct spacing afterwards.

I still think the problem lies in the fact that I have 6 classes with the beginning "CalcMain." One is CalcMain.class, my main class, and the 5 others are inner classes like CalcMain$addButtonListener.class.

I don't think I'm doing anything wrong. I get the same error when I generate a JAR file from Eclipse. It works fine on my computer, but nowhere else.

This post has been edited by AVReidy: 22 October 2011 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

#4 AVReidy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 09:52 AM

I made a very simple command line program as a test. I compiled it and put it in a JAR file. It runs fine on my computer, but when I run it on any other computer, I get an error (actually the same one as I get with my calculator):

Exception in thread "main" java.lang.UnsupportedClassVersionerror: MyMainClass : Unsupported major.minor version 51.0

at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)

And a few more lines... plus, at the end, it says:
Could not find the main class: MyMainClass. Program will exit.


I read about this error, and I think my JDK or compiler version is somehow too new. Apparently this would not be a problem if I had an older version.

My little test rules out the inner classes being a problem. It's just a problem with versions that I don't know how to fix.

From a Google search:
This exception can occur when the source is built targeting a JDK that is not supported by the JDK attempting to run it.

Since when do JAR files require the JDK?

This post has been edited by AVReidy: 22 October 2011 - 09:57 AM

Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10574
  • View blog
  • Posts: 39,151
  • Joined: 27-December 08

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 11:49 AM

Are the JREs up to date? Or are you using Java 7 and the client computers do not support this?
Was This Post Helpful? 1
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 04:44 PM

Actually your manifest should look like

Main-Class: CalcMain



I would qualify it as a bug, not solved since years, but the .mf needs an empty line to finish it

*Edited: seems the parser removed the empty line.. yoiu really need

Main-Class: CalcMain
<--- an empty line here

This post has been edited by pbl: 22 October 2011 - 04:46 PM

Was This Post Helpful? 1
  • +
  • -

#7 AVReidy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 04:56 PM

I checked my versions earlier and it turns out I compiled the program with the JDK 7 compiler and my other computers were running JRE 6.0.

Problem solved... it's kind of weird that I have to downgrade my JDK for my programs to run on mainstream computers with the 'official' version of Java.
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10574
  • View blog
  • Posts: 39,151
  • Joined: 27-December 08

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 05:11 PM

Until Oracle pushes their updates like Microsoft, do not count on widespread Java 7 support for a while. Plus, Java 7 has been freshly released. It will take a while for developers to trust it enough to fully embrace it. This happens with almost every new version of any technology.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Could not find the main class: CalcMain. Program will exit.

Posted 22 October 2011 - 06:57 PM

View PostAVReidy, on 22 October 2011 - 07:56 PM, said:

Problem solved... it's kind of weird that I have to downgrade my JDK for my programs to run on mainstream computers with the 'official' version of Java.

Don't know of any product that have support for a newer release
like reading a 2007 spreadsheet with a Excel 2000 program
Surely the same thing with C# or it produces miracles and if so you should stick to it :)
Was This Post Helpful? 0
  • +
  • -

#10 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2728
  • View blog
  • Posts: 11,470
  • Joined: 20-September 08

Re: Could not find the main class: CalcMain. Program will exit.

Posted 24 October 2011 - 02:26 AM

Quote

Problem solved... it's kind of weird that I have to downgrade my JDK for my programs to run on mainstream computers with the 'official' version of Java.


You don't need to downgrade. Just change the project JRE compliance in Eclipse to something that's as high as practical. 7 is too high. 6 could be too high in some cases. 5 should be pretty safe
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1