Results 1 to 3 of 3
  1. #1
    lexlukkia is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Default 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???

  2. #2
    lexlukkia is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Default

    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.

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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:
    Java 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:
    Java Code:
    javac Bicycle.java
    Press enter.
    You should see a class file appear in the current directory.
    Run it with:
    Java 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:
    Java Code:
    C:\java\bin>java Bicycle
    Exception in thread "main" java.lang.NoSuchMethodError: main

Similar Threads

  1. problem in wrapper class
    By binoympappachen in forum New To Java
    Replies: 4
    Last Post: 12-13-2007, 12:31 PM
  2. Class problem
    By Deagel in forum New To Java
    Replies: 1
    Last Post: 10-31-2007, 07:33 PM
  3. Problem calling another class
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 10-25-2007, 02:05 PM
  4. problem with date class
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 01:28 PM
  5. problem with scanner class:incompatible types
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •