Having trouble running java programm | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Having trouble running java programm

when I Type java C:\Users\and the location, I get Error: Could not find or load main class C:\Users\and the location

14th Dec 2016, 3:23 PM
Sergio Wehbe
7 Answers
+ 1
What do you want exactly to do ?
14th Dec 2016, 3:26 PM
Kemal Akgöl
Kemal Akgöl - avatar
+ 1
you have to compile first more than likely. In command prompt use javac C:\Users\Hello.java then use the java command like so java C:\Users\Hello this is an example replace with your actual location and application name respectively
14th Dec 2016, 3:49 PM
Cory Clapp
Cory Clapp - avatar
+ 1
I compiled it and it worked fine but when I want to run it I type java and the location but it doesn't work
14th Dec 2016, 3:53 PM
Sergio Wehbe
+ 1
when you navigate to the location there should be your .class file which shows you successfully compiled make sure when you use the java command that you dont include .java it should be java C:\Users\Hello if this stilll doesn't work your path to java might not be set correctly
14th Dec 2016, 4:02 PM
Cory Clapp
Cory Clapp - avatar
+ 1
Actually my path to java is correct and I tried to open the .class file with java and it still doesn't work
14th Dec 2016, 4:12 PM
Sergio Wehbe
+ 1
yeah you dont open the .class that answer below mine is incorrect, the java command is used on the .java file you just don't include. java when you run so if you have a program called hello.java you would type java hello also the prudent thing would be to ask if it has a main in your program as its not required to compile a file just to run.
14th Dec 2016, 4:25 PM
Cory Clapp
Cory Clapp - avatar
0
Run a .class File
14th Dec 2016, 3:28 PM
Sergio Wehbe