Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Basic Java problem


  • Please log in to reply

#1
Appreciated

Appreciated

    Member

  • Member
  • PipPip
  • 18 posts
trying to catch up on coursework form a manual but getting a problem when trying to compile the example file.

class car_5_1_1
{

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


class Example_5_1_1
{

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

}
}

can compile the car file ok but i get 2 erros with the Example one.
Cannot resolve symbol and it points to C in Car on both lines.
have tried change around caps etc on both but to no avail.

Help is appreciated...
  • 0

Advertisements


#2
magnus80a

magnus80a

    Member

  • Member
  • PipPip
  • 10 posts
Try and change
Car_5_1_1 c;
c = new Car_5_1_1();
to
car_5_1_1 c;
c = new car_5_1_1();
or change
class car_5_1_1
{

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

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

and rename the file to Car_5_1_1.java

Edited by magnus80a, 03 December 2005 - 05:36 PM.

  • 0

#3
Appreciated

Appreciated

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
i did.

i said that in my original post
  • 0

#4
magnus80a

magnus80a

    Member

  • Member
  • PipPip
  • 10 posts
Maybe the lack of constructor is causing it then?
Change:
class car_5_1_1
{

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

to
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{}
}

Edited by magnus80a, 04 December 2005 - 06:58 AM.

  • 0

#5
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
another thing to check:

class names are case sensitive.
car_5_1_1(in car_5_1_1.java) is not the same as Car_5_1_1(in Example_5_1_1.java)

try:
change car_5_1_1 in car_5_1_1.java to Car_5_1_1
rename car_5_1_1.java to Car_5_1_1.java

is there an import statement in Example_5_1_1.java?
import Car_5_1_1;
  • 0

#6
gust0208

gust0208

    Member

  • Member
  • PipPipPip
  • 311 posts
Hello,

The main problem with your code is that you need to make your "main" class public by changing:
"class Example_5_1_1" to "public class Example_5_1_1" and as stated in a previous response, the class names are case sensitive and I changed "class car_5_1_1" to "class Car_5_1_1". I was then able to compile it with no problems. I have attached the modified java file and named it in concordance with the main class, Example_5_1_1.java.

Here is the final java code for you to cut-n-paste as well if wanted:
----------------------------------------------------------------------------
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() ;

}
}


Cheers,
Tom

trying to catch up on coursework form a manual but getting a problem when trying to compile the example file.

class car_5_1_1
{

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

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

}
}

can compile the car file ok but i get 2 erros with the Example one.
Cannot resolve symbol and it points to C in Car on both lines.
have tried change around caps etc on both but to no avail.

Help is appreciated...

Attached Files


  • 0

#7
Appreciated

Appreciated

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
i still couldn't get it working and now the strangest thing is happening.

from my documents i have it in a sub folder going say my documents\college\year2\lab5\

and i get the errors when trying to compile the example file.
when i cut and paste the files to the directory my documents\college they compile fine

and this has nothing got to do with the compiler not working in the other folders. i can run other java files from the lab5 folder also but only ones that are saved in one file.

very confused

Edited by Appreciated, 05 December 2005 - 02:16 PM.

  • 0

#8
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
let's look at the coding problem first.

please post the code that fails along with a good description of the error message.
does it compile? does is compile, but fail when running?

look carefully at the command stack(the long list of files and line numbers) that occurs after an error. find your filename(Example_5_1_1.java or Car_5_1_1.java) and post the filename(s) and line number. generally the offending code will be near the top of the java error message.
  • 0

#9
coyne20

coyne20

    Member

  • Member
  • PipPip
  • 35 posts
Have you tried declaring your class public?
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP