-
Error during running
Hi,
I am an engineering student IT department.
I have error during running an simple java program.
I have set the path correctly and its compiling correctly but when i give
java filename it shows an error saying exception in main thread.
The code i used is
Code:
class ak
{
public static void main(String arg[])
{
System.out.println("hai");
}
}
For me appletviewer is working correctly problem only with when i run java program.
Please help me solve my problem
-
What do you mean by "problem only with when i run java program"?
Dit you exported it into a jar file?
Can you post the error please?
And if you post a code please use CODE-tags.
[CODE]Your code goes here.[/CODE]
-
when i compile that piece of code no error but when i run the program i get an error
saying Exception in no main foundI didnt use any jar and all
-
Copy, paste and post the command you are using and the exact and entire error message you receive.
To compile and run that code from the directory containing ak.java you would typically use something like:
Code:
> javac -cp . ak.java
> java -cp . ak
Note that "ak" is not a very good name for a Java class. These start with a capital letter (hance, Ak). Part of the reason for this is that consistent case naming conventions help reduce errors like specifying the class name incorrectly on the command line.
-
How did you compile and run your code, as pbrockway2 says please provide more details here. So it's easy to help you.
-
compiled using javac ak.java
while running
C:\>java ak
Exception in thread "main" java.lang.NoSuchMethodError: main
-
definitely not a coding problem, but you most likely have something wrong with your classpaths or whatnot. are you aware of packages? trying putting your class into a package and running it that way. it should work with the default (no defined) package, but it's generally frowned upon to do so.
-
Yes, so the next thing to know is all about the classpath setup. But if the classpath is not setup correctly, that javac command complain about that "javac is not recognized command......"