Results 1 to 20 of 42
- 03-01-2012, 08:25 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Java Could not find main class...
Ok I've searched and searched everywhere and just don't know where to look next!
Right so I'm using eclipse and have named my files the same as my project for example HelloWorld.java and my public class is HelloWorld, I exported the project as a executable java file through eclipse.. So I thought great! This will run on it's own! but no.... I've tried and tried and just can't seem to fix it!
So my problem!
I've double checked my MANIFEST.MF file loads of times and my file names etc.. here is my manifest file..
And my java fileJava Code:Manifest-Version: 1.0 Class-Path: . Main-Class: test.HelloWorld
Now I have no idea why this won't run or work.. I keep getting the message: " Could not find the main class. HelloWorld. program will exit"Java Code:package test; public class HelloWorld { /** * @param args */ public static void main(String[] args) { System.out.print("Hello world"); } }
Why oh Why is this happening? For what I can see my files are in the right places within the HelloWorld.jar file that i exported using Eclipse so it should be fine??
Anyhoot, hope you can understand any help is greatly appreciated as I don't know what I'm doing wrong!!
Thanks in advanced!!
/Diciwales
- 03-01-2012, 08:50 PM #2
Re: Java Could not find main class...
Try running it in a command prompt window and see if you get a more complete error message.
Open a command prompt window, change to the folder with the jar file and enter:
java -jar <THEJARFILENAME>.jar
If on Windows:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 03-01-2012, 09:10 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
- 03-01-2012, 09:14 PM #4
Re: Java Could not find main class...
Is that output from the program you posted? The text of the output is different.
HelloWorld
vs
Hello world
Details are important in programming.
- 03-01-2012, 10:00 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
No it was displayed Hello World, I just typed it wrong from the cmd here is it selected all
:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>java -jar HelloWorld.jar
Hello world
C:\Users\Administrator>
Regards
- 03-01-2012, 10:04 PM #6
Re: Java Could not find main class...
What happened to the error message you were getting?
- 03-02-2012, 12:59 PM #7
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
The error message is still there.. it happens when i double click the application
so confused.. just uninstalled and re-installed java.. no luck
Regards
- 03-02-2012, 01:22 PM #8
Re: Java Could not find main class...
What version of Windows are you on?
Do you know about the registry and the registry editor?
The registry contains the commandline the OS uses when it executes files.
Here is the registry contents for .jar files on my XP machine:
[HKEY_CLASSES_ROOT\jarfile\shell\open\command]
@="\"C:\\Program Files\\Java\\jre1.6.0_07\\bin\\javaw.exe\" -jar \"%1\" %*"
- 03-02-2012, 08:02 PM #9
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
Hi i'm on windows 7,
how do i find the registry contents for .jar files using CMD?
Thanks again for your help so far ! much appreciated
- 03-02-2012, 08:15 PM #10
Re: Java Could not find main class...
Execute the regedit command. It has a windows explorer like interface. Do a Find for .jar. It wiil be in a long list of all the extensions that windows knows about. The right hand window will show (Default) on the left and will have a name in the Data column. On my system the name is jarfile.
Do a Find for the name you see there. Under that name will be shell and command. Open command and see if it looks a little like what I posted in #8.
Use the export menu item to export the contents to a file that you can EDIT/not merge and post here.
- 03-03-2012, 09:30 AM #11
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
- 03-03-2012, 01:03 PM #12
Re: Java Could not find main class...
You didn't follow all the instructions. You need to do two Finds.
The first for ".jar" which you did and got the "jarfile" value. That looks OK.
Now you need to do the second Find for "jarfile" which will have the command line.
- 03-03-2012, 01:46 PM #13
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
ok sorry, here is the next part
Thanks againWindows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\jarfile]
@="Executable Jar File"
[HKEY_CLASSES_ROOT\jarfile\shell]
[HKEY_CLASSES_ROOT\jarfile\shell\open]
[HKEY_CLASSES_ROOT\jarfile\shell\open\command]
@="\"C:\\Program Files (x86)\\Java\\jre6\\bin\\javaw.exe\" -jar \"%1\" %*"
- 03-03-2012, 01:48 PM #14
Re: Java Could not find main class...
That looks a lot like mine.
Is your PC 64bit or 32bit? I forget what the (x86) in the path means.
- 03-03-2012, 01:56 PM #15
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
64bit
- 03-03-2012, 01:59 PM #16
Re: Java Could not find main class...
What is the PATH environment set to? Open a command prompt and enter: path
Does it have a pointer to the same bin folder that is in the command line in the registry?
- 03-03-2012, 02:02 PM #17
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
that's what is displayed when I type Path into the CMDMicrosoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>path
PATH=C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Sys tem32\WindowsPowerShell\v1.0\
C:\Users\Administrator>
- 03-03-2012, 02:17 PM #18
Re: Java Could not find main class...
What version of java do you get when in a CMD window? Enter:
java -version
- 03-03-2012, 02:28 PM #19
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: Java Could not find main class...
RegardsMicrosoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
C:\Users\Administrator>
- 03-03-2012, 02:34 PM #20
Similar Threads
-
Could not find or load main class: c:\java\HelloWorldApp
By Atticus in forum New To JavaReplies: 10Last Post: 02-02-2012, 08:26 PM -
Could not find the main class: java. Program will exit
By thewonkits in forum New To JavaReplies: 3Last Post: 01-11-2012, 11:56 AM -
newbie question: Error: Could not find or load main class Java Result: 1
By ideaman in forum New To JavaReplies: 7Last Post: 01-01-2012, 12:29 PM -
Error: Could not find or load main class Ops.java
By Javasubbu in forum New To JavaReplies: 4Last Post: 10-05-2011, 10:52 PM -
Java virtual machine:Could not find Main Class: d. Program will exit.
By xHolyMariox in forum New To JavaReplies: 4Last Post: 08-22-2011, 03:42 PM


1Likes
LinkBack URL
About LinkBacks


Bookmarks