Results 1 to 5 of 5

Thread: Getting an Error while Compiling the Java program

  1. #1
    Join Date
    Aug 2006
    Posts
    287

    Getting an Error while Compiling the Java program

    I am getting an Error while compiling the following file written in Java.

    1. class car_5_1_1
    {
    String licensePlate; // e.g. "96 C 1"
    double speed; // in mph
    double maxSpeed; // in mph
    }

    2. class Example_5_1_1
    {
    public static void main(String args[])
    {
    Car_5_1_1 c;
    c = new Car_5_1_1() ;
    }
    }

    While compiling the car file, I am not getting any error. But when I try to compile the Example file I am getting the 2 errors. I tried a lot but cannot resolve my problem. Please help me by telling where I went wrong.!!
    Dimension 1100 (FMY032J) mini-tower
    2.53ghz Intel Pentium 4
    80 gig nfts HDD
    512 RAM
    Main circuit board: Dell 0CF458
    BIOS: Dell A00
    Display: Intel(R) 82865G Graphics Controller [Display adaptor]
    Multimedia: Sound MAX Integrated Digital Audio
    Windows XP Home SP2

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Getting an Error while Compiling the Java program

    I would like to suggest you to change the following things from the Example file:
    Your Actual Code is
    Car_5_1_1 c;
    c = new Car_5_1_1();
    Try to change this coding to
    car_5_1_1 c;
    c = new car_5_1_1();
    Hope that changing the case will solve your problem. By doing this you will not get the error while Compiling the Java program.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Getting an Error while Compiling the Java program

    If doing the changes told by 'Zecho' is not making any changes then try to change the code as below :
    Your actual code of class file :
    class car_5_1_1
    {
    String licensePlate; // e.g. "96 C 1"
    double speed; // in mph
    double maxSpeed; // in mph
    }

    do the following changes :
    class Car_5_1_1
    {
    String licensePlate; // e.g. "96 C 1"
    double speed; // in mph
    double maxSpeed; // in mph
    }
    Also don't forget to rename the file to Car_5_1_1.java before compiling it.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Getting an Error while Compiling the Java program

    According to me the error that you are getting is due to not using the constructor. The lack of the constructor may cause this problem. So try to use the following coding :

    class car_5_1_1
    {
    String licensePlate; // e.g. "96 C 1"
    double speed; // in mph
    double maxSpeed; // in mph
    public car_5_1_1{}
    }

    Hope that your error will get resolved after using the constructor.

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Getting an Error while Compiling the Java program

    In your coding you need to make your "main" class public and this is the main cause of the problem. You can do the changes like "class Example_5_1_1" to the "public class Example_5_1_1". Also the class names are case sensitive. I made some changes I was able to compile the both files without any error.

    class Car_5_1_1
    {
    String licensePlate; // e.g. "96 C 1"
    double speed; // in mph
    double maxSpeed; // in mph
    }

    public class Example_5_1_1
    {
    public static void main(String args[])
    {
    Car_5_1_1 c;
    c = new Car_5_1_1() ;
    }
    }

Similar Threads

  1. Compiling and Executing a Python program.
    By Blake's in forum Software Development
    Replies: 3
    Last Post: 15-02-2012, 04:46 PM
  2. Eclipse not compiling my Java file
    By Valliy in forum Software Development
    Replies: 4
    Last Post: 25-07-2010, 12:30 AM
  3. Error compiling easyapache
    By Who is it in forum Software Development
    Replies: 6
    Last Post: 16-06-2010, 04:13 AM
  4. error when compiling clamav-0.95.tar.gz
    By KennedII in forum Networking & Security
    Replies: 4
    Last Post: 24-04-2010, 04:35 AM
  5. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,555,520.40585 seconds with 17 queries