Reputation: 703
package p1;
class a {
public static void main(String[] argument) {
//nothing
}
}
And when I type java p1.a
in command prompt, it always say Main class not found
? Why so?
Can any one help me out? Why this is happening? Is the syntax correct?
Upvotes: 0
Views: 112
Reputation: 8946
First as there is a package p1;
you need to create the folder p1
and put the file inside it then as you said if you folder p1
is in desktop, then open the cmd in desktop then compile it by javac p1/a.java
and run it by java p1.a
Upvotes: 1
Reputation: 436
Read this
When you create a package, you have to compile the package with -d
option in javac. Then try executing the main class.
Upvotes: 1
Reputation: 36304
you need to do javac
first.. javac
generates a .class
file. And try using the full (absolute) path when using java
command.
Upvotes: 1