Unable to run java from CMD
NickName:John Schwartz Ask DateTime:2016-01-29T02:09:34

Unable to run java from CMD

I'm not sure what I'm doing wrong... I'm following several YouTube videos and I'm still unable to run my java program from the command prompt.

VERY first thing I did in cmd was: set path="[copied URL to the JDK bin directory]"

Then I used 'cd' to get all the way to my homework directory, containing 4 java files.

Then I typed in 'javac hangman.java' to compile it... (Let's just say it was hangman)

Finally, I typed in 'java hangman'

And it says: "Error: Could not find or load main class hangman" inside my cmd.

What have I done wrong?

(I'm using Windows 10 if this somehow makes a difference.)

Copyright Notice:Content Author:「John Schwartz」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35068877/unable-to-run-java-from-cmd

Answers
Armaiti 2016-01-28T18:14:51

Two things:\n\n\nMake sure your class name starts with capital letter, Hangman instead of hangman.\nMake sure you have public static void main(String[] args) method \n",


Jessica 2016-01-28T18:20:52

\nFirst you have to indicate where the java file is.\nBut if you are in the same directory as your class to compile => error not find main class.\njavac namefile.javac\njava namefile\n\n\nFor exemple, I want to compile Car.java and its path is: Desktop > CarsProyects > src > carsPackage.\n\nif I'll try: \ncd Desktop\ncd CarsProyects\ncd src\ncd carsPackage\njavac Cars.java\njava Cars\n\nI would have the same error as you 'main class not load or not find' \nSo try this one (cd carsPackage >.. ):\n\ncd Desktop\ncd CarsProyects\ncd src\njavac Cars.java\njava Cars\n\nI hope this help!",


More about “Unable to run java from CMD” related questions

Unable to run java from CMD

I'm not sure what I'm doing wrong... I'm following several YouTube videos and I'm still unable to run my java program from the command prompt. VERY first thing I did in cmd was: set path="[copied...

Show Detail

unable to run compiled .class java file in Win7 cmd

issue is the following when trying to use Apache's java telnet solution in win7 cmd: I keep getting "Error: Could not find or load main class TelnetClientExample.class" message when trying to run a

Show Detail

Unable to run Cordova project from cmd

I am unable to run Cordova project from cmd by executing commands cordova run android and cordova emulate android. But successfully run form Android studio. Can anyone help to analyse the problem? ...

Show Detail

Run multiple cmd commands from java

I want to run multiple cmd commands succesively from java code one after the other. I want to use this one command line application which creates ssh connection and I want to run multiple commands

Show Detail

Able to compile but unable to run Java from cmd with jar files

I have a java file which uses jfreechart libraries, uses a text file from local drive and displays graph. Runs fine with eclipse. However, I want to run this from cmd prompt, other simple Java file...

Show Detail

Run Jar related .Java from cmd

I am trying to do "javac Classname.java" from cmd prompt, and this Classname.java requires Jfreechart libraries/jars, and runs fine if compiled from Eclipse (because project package has j...

Show Detail

How to run Java from cmd?

I have a multithreaded program that imports JSON that I want to run through CMD but right now, I can't because it says its not imported. How can I fix this problem so that I can always run the prog...

Show Detail

java run cmd commands

I have some problem about run windows cmd ,when I run my code on GEL or some java tool,it works,but it run error that windows can't find "pscp".However,I export execute jar from eclipse and java -j...

Show Detail

Java run cmd security

I am trying to run an example to start the CMD. I am getting an error from the execution. The file is of course in the right place. So my guess is that this is a permission error. Can someone lead ...

Show Detail

How to run Java from CMD, with Apache Commons libraries

I've made a program which uses the Apache Commons io and lang3 libraries. It runs fine in eclipse but I can't get it to run from cmd and it comes up with the following error: Exception in thread ...

Show Detail