posted 20 years ago
It's my first time learning java. I decided to learn from this book but this book is giving me a headache. I have spent more than 10 hours to figure out how to run this thing. I have succeeded in compliling it by typing javac Party.java on command prompt, but there's an error when I try to run it by typing java Party. The error message is
Exception in thread "main" java.lang.NoSuchMethodError: main
I did have look at replies on other topics that explained why the message 'NoSuchMethod Error: main' appeared for many different reasons, but I've tried what they said, it didn't work. The source code looks like this:
-------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class Party{
public void buildlnvite(){
Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Schoot me");
Panel p = new Panel();
p.add(l);
}
}
------------------------------------------------------------
and then I saved it as Party.java.
I know that this source code is missing 'void main', but it is supposed to work because the author says so. I've tried other source codes that had 'void main' in them and they worked, but I really should know how to run this thing when it doesn't have 'void main' because many examples given in this book are written that way.
I think the reason why it doesn't work is because I did not set up java properly. Head First Java says setting up java requires the following:
#1. a 1.5 or greater Java 2 Standard Edition SDK
#2. API documentation since it is not included in SDK (according to the book.)
#3. text editor
#4. Adding an entry to your PATH environment variable that points to the /bin directory inside the main Java directory.
The way I followed it was like this:
I downloaded J2SE v 1.4.2_08 SDK from java.sun.com and installed
C:\j2sdk1.4.2_08
here.
I also downloaded J2SE 1.4.2 Documentation which I think is the API documentation and extracted
C:\Documents and Settings\admin\My Documents\downloaded files\j2sdk-1_4_2-doc\docs
here. This file has files in it called api,images,guide,relnotes,install-notes,tooldocs. (I have no idea what these are)
I didn't do anything about #3 since I had notepad.
For #4, I chose start, setting, control panel, double-click system,advanced tab, environment variable, and then I edited the already existing environment variable PATH(on the bottom, not user variable) and gave this directory C:\j2sdk1.4.2_08\bin
and selected ok.
After failing to run it on Command prompt, since the book says to run the program by starting the Java Virtual Machine with the Party.class file, I tried to find JVM in C:\j2sdk1.4.2_08, but I couldn't find it. Neither way worked.
What would I possibly doing wrong? setting up JAVA?
Thanx in advance.