This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes I have problem with Compiling and Runing Java file with JDK Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "I have problem with Compiling and Runing Java file with JDK" Watch "I have problem with Compiling and Runing Java file with JDK" New topic
Author

I have problem with Compiling and Runing Java file with JDK

Bashir Mirzad
Greenhorn

Joined: Nov 28, 2001
Posts: 25
Hi, Every body
I have a problem with the jdk, when I am going to compiling my java file in Command Prompt I am typing JAVAC name_of_file.java
then I can compile but when I am going to run this file I am typing JAVA name_of_file, I cna not run the file
it give me this message
C:\java test
Exceptin in thread "main" java.lang.No.SuchMethodError: main
thanks
Bashir
Brent Worden
Ranch Hand

Joined: Nov 26, 2001
Posts: 50
Give this a shot:
java -cp . test

------------------
Brent Worden
http://www.brent.worden.org/


Brent Worden
Altaf Raja
Greenhorn

Joined: Dec 05, 2001
Posts: 5
Originally posted by Bashir Mirzad:
Hi, Every body
I have a problem with the jdk, when I am going to compiling my java file in Command Prompt I am typing JAVAC name_of_file.java
then I can compile but when I am going to run this file I am typing JAVA name_of_file, I cna not run the file
it give me this message
C:\java test
Exceptin in thread "main" java.lang.No.SuchMethodError: main
thanks
Bashir

type this:
c:\ set classpath=.;
then run
c:\java urClassFile
hope this works

------------------
Bashir Mirzad
Greenhorn

Joined: Nov 28, 2001
Posts: 25
Hi Guys
I still have the problem, I am using Win2000 and set the classpath .; and I a have the path for jdk like this
C:\jdk1.3.0_02\bin, I can compile my program but I can not run that
thanks
[This message has been edited by Bashir Mirzad (edited December 05, 2001).]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Remove the semicolon from your classpath statement.

Also make sure that if your class is inside a package, that the *.class file is placed inside an appropriate folder structure (one that reflects the package structure).

I'm also moving this to Java In General - Beginners
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
It could be a problem with your code.
In your name_of_file.java file you must define a method called 'main()', and it must be defined like this:
public static void main(String[] args) { _your_code }
or like this:
public static void main(String args[]) { _your_code }
If you define 'main()' any other way then it becomes an ordinary method and not the start point for your program.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: I have problem with Compiling and Runing Java file with JDK
 
Similar Threads
I have problem with Compiling and Runing Java file with JDK
Getting error: Bad version number in .class file
How do you read a file in Servlet?
Access Modifiers
Error while trying to run Tomcat for servlets