1

I have a .java file which i compiled in a package named "Mypack",using command line as follows

javac -d . file_name.java     // The "." specifies the current working directory which was the desktop

so it creates a folder on the desktop named "Mypack"(The package name), in the folder the .class file for my program is placed.Now i did the following

java -classpath "C:\Users\LoRd CuRZon\Desktop\Mypack" file_name     //  Error Could not find or load main method

Even if i go into the directory "Mypack" and launch command prompt from that directory and try to run the program i still get the same error.

4
  • What error do you get? Commented Nov 29, 2015 at 10:41
  • have you added any package statement into source file , then please provide me. Commented Nov 29, 2015 at 10:42
  • is it a simple java file or it contains main method? Commented Nov 29, 2015 at 10:42
  • This works but i still don't understand why cant i just go to the directory of the file and write java file_name ? Commented Nov 29, 2015 at 12:35

3 Answers 3

4

run it as likewise from Desktop,

c:/.../Desktop> java Mypack.file_name
Sign up to request clarification or add additional context in comments.

Comments

1

java command requires fully qualified name .

so from desktop run java Mypack.classname

Comments

1

If you have this error:

 Error Could not find or load main method

That means you don't write a main method in you code try to write it. But befor to do those steps: Fo compiling a programme do this:

java Mypack.file_name

To run it do like this:

java Mypack.classname

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.