Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  No main method can be found [FIXED]  (Read 729 times)
0 Members and 1 Guest are viewing this topic.
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Posted 2014-06-16 18:11:05 »

  Hello everyone.
  First of all, I think this post is only for those who are using no IDEs, only the Java Development Kit and cmd.
  Ok. I'm having troubles with executing my projects. Yesterday, all worked well. In cmd, when in my project's repertory, when I wrote
1  
java <class containing the main method>
, all worked fine and the project ran. But... Now, it won't open the project (even those I had done before) using the command, saying I have no main method that can be found. It seems I have to do
1  
java -cp "%cd%" <class containing the main method>
Undecided
  One change I have noticed is that the
1  
echo %CLASSPATH%
command returns "null" Shocked Before, I'm sure it was something more like "%classpath%;c:\Users etc". Moreover, no matter what I set it to (with the
1  
set %CLASSPATH%
command) its value won't change persecutioncomplex
  I've tried installing Java again and it changed nothing. Could some charitable god help me out of this now ? :3 Thanks a LOT !
    J0
Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #1 - Posted 2014-06-16 18:14:24 »

Can you show us a complete example from start to finish, including the actual code you're trying to run (the smaller the better) as well as the text copied directly from the command line?

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2014-06-16 18:18:27 »

There is very little information with which to help you. Could you also show the directory structure?

Also as far as I know, there is no CLASSPATH global environment variable.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #3 - Posted 2014-06-16 18:20:53 »

  Sure. Here's an extremely small code (don't think we can actually do smaller) :
1  
2  
3  
class Main{
    public static void main(String [] args){
        System.out.println("Java works!");}}

  As I said, cmd won't allow me to run it (not finding the main method)... I won't copy the text from cmd as my computer is set to French, but this is approximately what it's saying : "Error: it is impossible to find or load the main method."
  Thanks Wink
Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #4 - Posted 2014-06-16 18:21:38 »

We need to see exactly what you're typing into the command line, as well as the directory structure where you're executing those commands.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #5 - Posted 2014-06-17 08:37:05 »

We need to see exactly what you're typing into the command line, as well as the directory structure where you're executing those commands.
  Well, as you want. I have my code here :

C:\Users\Me\Desktop\Project\Code

  And my main class is called Main. So what I type is:
1  
2  
3  
cd Users\Me\Desktop\Project\Code
javac Main.java
java Main
Offline Endos
« Reply #6 - Posted 2014-06-17 09:19:49 »

We need to see exactly what you're typing into the command line, as well as the directory structure where you're executing those commands.
  Well, as you want. I have my code here :

C:\Users\Me\Desktop\Project\Code

  And my main class is called Main. So what I type is:
1  
2  
3  
cd Users\Me\Desktop\Project\Code
javac Main.java
java Main


Maybe you has a package defined in Main?

1  
java yourpackage.Main

Bored Birds - End with your boredom for Android
Retroships - Space Shooter for Android
Ultimate - 2D Side-Scrolling Platformer project
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #7 - Posted 2014-06-17 09:33:42 »

Nope, no packages...
Offline Roquen
« Reply #8 - Posted 2014-06-17 09:38:27 »

And "Main.class" is indeed in the directory?  (It's been eons since I've used javac). 
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #9 - Posted 2014-06-17 10:02:48 »

And "Main.class" is indeed in the directory?
Sure it is Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline imagnity

Junior Member


Medals: 2
Projects: 1
Exp: 11 years


Coding = Life;


« Reply #10 - Posted 2014-06-17 10:43:46 »

Set JAVA_HOME to your variable path. Do a google search.

Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #11 - Posted 2014-06-17 12:22:44 »

Set JAVA_HOME to your variable path.
  I'll try and do that ! Thanks a lot ! Cool
    J0
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #12 - Posted 2014-06-17 12:37:09 »

Set JAVA_HOME to your variable path. Do a google search.
  Thank you SO MUCH *-*
  I dunno why it used to work, then stopped working, but never mind... IT WORKS ! Roll Eyes
    J0
Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #13 - Posted 2014-06-17 13:32:39 »

That fix really doesn't make any sense. If you're just using java and javac, your JAVA_HOME variable is never read. The only thing that matters is your PATH, and if java and javac can be found, your PATH is fine.

I would bet that you were simply in the wrong directory or something, and fixed yourself without realizing it.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #14 - Posted 2014-06-17 13:35:54 »

That fix really doesn't make any sense. If you're just using java and javac, your JAVA_HOME variable is never read. The only thing that matters is your PATH, and if java and javac can be found, your PATH is fine.

I would bet that you were simply in the wrong directory or something, and fixed yourself without realizing it.
  I don't know either how this fixed it, but it actually DID, so sorry, but it seems you're wrong. I'm absolutely SURE I didn't change directory. Cranky
  Never mind though. It works, so that is enough for me for now Tongue
Offline imagnity

Junior Member


Medals: 2
Projects: 1
Exp: 11 years


Coding = Life;


« Reply #15 - Posted 2014-06-17 14:13:12 »

That fix really doesn't make any sense. If you're just using java and javac, your JAVA_HOME variable is never read. The only thing that matters is your PATH, and if java and javac can be found, your PATH is fine.

I would bet that you were simply in the wrong directory or something, and fixed yourself without realizing it.

You are right cmd doesn't read that but after all these years.. sometimes redirection with punch line works meaning when you search to set up java_home in google and find articles on it, you will usually be also asked to update your path to %JAVA_HOME%\bin which gets the job done. I admit though I was a bit lazy when answered.

Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #16 - Posted 2014-06-17 14:17:00 »

you're wrong.

I issue you a challenge: change your JAVA_HOME back to whatever it was before. I bet it still works.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #17 - Posted 2014-06-17 14:19:21 »

I issue you a challenge
  Anyway, if it didn't change anything with my problem, could you explain me how I now have it all right now ? Huh
    J0
Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #18 - Posted 2014-06-17 16:30:34 »

Anyway, if it didn't change anything with my problem, could you explain me how I now have it all right now ? Huh

What do you think JAVA_HOME is used for?

JAVA_HOME is used by third party programs that need to know where Java is but don't want to rely on your PATH. You can also use JAVA_HOME in your PATH to avoid changing your PATH whenever you upgrade Java.

Both java and javac worked for you, which means that your PATH was working fine. Java doesn't look at JAVA_HOME at all.

I predict that you exited a window or command line to go change your JAVA_HOME, then reopened it in the correct location. It was not the changing of the JAVA_HOME that fixed your problem, but the reopening of the window or command prompt. If you didn't exit the command prompt, then it *definitely* wasn't changing JAVA_HOME, as those changes are not detected by command prompts that are already open.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #19 - Posted 2014-06-17 16:54:19 »

I predict that you exited a window or command line to go change your JAVA_HOME, then reopened it in the correct location.
I definitely didn't have the incorrect repertory open in my cmd, I've had this problem for about 2 days and tried a few billion times Grin
Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #20 - Posted 2014-06-17 16:57:52 »

I definitely didn't have the incorrect repertory open in my cmd, I've had this problem for about 2 days and tried a few billion times Grin

Fair enough. All I'm saying is that changing your JAVA_HOME wasn't actually what fixed your problem. It's cool that you got it working, but next time you encounter this problem, changing JAVA_HOME won't fix it.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline imagnity

Junior Member


Medals: 2
Projects: 1
Exp: 11 years


Coding = Life;


« Reply #21 - Posted 2014-06-17 17:09:31 »

I definitely didn't have the incorrect repertory open in my cmd, I've had this problem for about 2 days and tried a few billion times Grin

Fair enough. All I'm saying is that changing your JAVA_HOME wasn't actually what fixed your problem. It's cool that you got it working, but next time you encounter this problem, changing JAVA_HOME won't fix it.

Sane explanation - It's possible that he had %JAVA_HOME%\bin in his path but JAVA_HOME was missing in his system variables. Windows wouldn't complain about that. Adding JAVA_HOME fixed the problem.

Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #22 - Posted 2014-06-17 17:14:19 »

Sane explanation - It's possible that he had %JAVA_HOME%\bin in his path but JAVA_HOME was missing in his system variables. Windows wouldn't complain about that. Adding JAVA_HOME fixed the problem.
  Ehe, that must be it Cheesy
  Thanks to everyone who posted here ! Smiley
    J0
Offline KevinWorkman

JGO Wizard


Medals: 68
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #23 - Posted 2014-06-17 17:20:43 »

Sane explanation - It's possible that he had %JAVA_HOME%\bin in his path but JAVA_HOME was missing in his system variables. Windows wouldn't complain about that. Adding JAVA_HOME fixed the problem.

Again, no. His javac and java commands worked fine, so there was nothing wrong with his PATH variable. That's the only thing you need to set in order to use javac and java. Neither java nor javac use the JAVA_HOME variable.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline J0

Senior Newbie


Exp: 4-6 months


Java works!


« Reply #24 - Posted 2014-06-17 17:24:48 »

  In fact... It doesn't REALLY matter, what was going wrong, is it ? Tongue
Offline imagnity

Junior Member


Medals: 2
Projects: 1
Exp: 11 years


Coding = Life;


« Reply #25 - Posted 2014-06-17 17:25:48 »

Sane explanation - It's possible that he had %JAVA_HOME%\bin in his path but JAVA_HOME was missing in his system variables. Windows wouldn't complain about that. Adding JAVA_HOME fixed the problem.

Again, no. His javac and java commands worked fine, so there was nothing wrong with his PATH variable. That's the only thing you need to set in order to use javac and java. Neither java nor javac use the JAVA_HOME variable.

I thought they used to run..and then gave up..

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (78 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (58 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (35 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!