Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-18-2007, 04:01 AM
Member
 
Join Date: Nov 2007
Posts: 2
lexlukkia is on a distinguished road
Im new to java. how do i fix the problem with class
im just new to java. my problem is, i copy and paste a code from java.sun.com to a notepad, i save it as class.java.

the code is:

private class Bicycle {

private int cadence;
private int gear;
private int speed;

public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}

public int getCadence() {
return cadence;
}

public void setCadence(int newValue) {
cadence = newValue;
}

public int getGear() {
return gear;
}

public void setGear(int newValue) {
gear = newValue;
}

public int getSpeed() {
return speed;
}

public void applyBrake(int decrement) {
speed -= decrement;
}

public void speedUp(int increment) {
speed += increment;
}

}



what seems to be the problem???
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-18-2007, 04:04 AM
Member
 
Join Date: Nov 2007
Posts: 2
lexlukkia is on a distinguished road
it always happen in the line of
"public class ClassName{}"
even in other sample program. as long "public class ClassName" exist in the program, it always has a error. why?? please help.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-18-2007, 06:47 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
The class name that has the public modifier (and that usually contains the main method) in your source file must have the same name as the file name.
So if you pasted the class into an empty document and change (the access modifier [private to public] in the) the class signature to:
Code:
public class Bicycle
Now you save the document as "Bicycle.java" This file name that you save it as must be the same as the name of the class - case is important. Then you compile it with:
Code:
javac Bicycle.java
Press enter.
You should see a class file appear in the current directory.
Run it with:
Code:
java Bicycle
Press enter.
Since you do not have a main method in the class you should see something like this in the console:
Code:
C:\java\bin>java Bicycle Exception in thread "main" java.lang.NoSuchMethodError: main
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in wrapper class binoympappachen New To Java 4 12-13-2007 02:31 PM
Class problem Deagel New To Java 1 10-31-2007 09:33 PM
Problem calling another class adlb1300 New To Java 3 10-25-2007 04:05 PM
problem with date class gabriel New To Java 3 08-03-2007 03:28 PM
problem with scanner class:incompatible types fred New To Java 1 07-20-2007 09:02 AM


All times are GMT +3. The time now is 03:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org