my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Non-Default Constructor problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Non-Default Constructor problem" Watch "Non-Default Constructor problem" New topic
Author

Non-Default Constructor problem

celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
Hi All,

I wonder if you could help me. I have the following code, which creates a JPanel with a 'Figure of eight' formation of gifs to represent an LED:

When i try to call this from another class, eg:

I get a compilation error: Method not found: Constructor LED( int ).

Obviously there is a constructor LED(int) in the LED class. Why can't other classes see it?

Thanks a million,
Celine


We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br />- Robert Wilensky
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi celine
I have interested to test your program.
In your situation, the compiler can not find out the constructor in the LED class, but can find out the LED class.
Method not found: Constructor LED( int ).
Cound you test the following that you wrote the constructor which overrides the default one?

If the compiler can not find out this constructor too, then you can remove both of these constructor and let the compiler find out the default one.
I wonder if you can tell me the result after testing the above procedure
Hope to find out some interesting event


Francis Siu
SCJP, MCDBA
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
hi

you do not pass an but an to the Constructor. and there is no Constructor accepting an .
I did not read your code so i dont know which is wrong (wether you need to pass an array or an int) but you need to change one of them...

pascal
celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
Hi Pascal & Siu

Thanks for your help. Sorry Pascal, please ignore the 'main' method in class LED. I am calling constructor new LED( int ) from another class.

Siu, i tried your suggestion & i the default constructor is found. No error message is received. Now i'm really confused!!!

Thanks again,
Celine
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
then please show the code where you call it (and remove the main method since ot wont compile with that)

p
Hans Achternaam
Greenhorn

Joined: Aug 18, 2004
Posts: 3
Hi Celine,

I copied and compiled the code and had no problem with. Including the constructor call from another class.

BTW are you using a Sun SDK ? This shouldn't matter but since you get an error saying LED( int ) and not LED(int) I just wonder. I'm getting the last error when trying to call a constructor which takes an int and the compiler can not find it. Try this in your class: new LED(1) instead of new LED( 1 )
celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
Hi Hans,
Yeah, i'm using SunONE Studio. Spaces like this would make a difference? Oh no!!! The people in the cattle drive won't like me taking them out!!
Haha! I'll try that now - thank you all very much for your help.

Hi Again Pascal,
Here's the code calling the LED( int ) constructor:


Thanks again,
Celine
Hans Achternaam
Greenhorn

Joined: Aug 18, 2004
Posts: 3
Nope, spaces should not make a difference.
Your (new posted) code compiles also without a problem here.

Sorry, no idea what the problem is.
[ August 18, 2004: Message edited by: Hans Achternaam ]
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Spaces like this would make a difference? Oh no!!!

Give us five words, "We never do that again"
Of course, I seldom do it.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

I don't see in your code where you are calling the LED(int) constructor. I see you calling a LEDPanel, but i don't see where that is defined.

i was able to get your code to compile by changing the lines

to


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
ar...yes
error message should be: Method not found: Constructor LEDPanel( int ).
Or
class not found: LEDPanel
[ August 18, 2004: Message edited by: siu chung man ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non-Default Constructor problem
 
Similar Threads
Accessing JFrame contents
Images do not display correctly
Displaying panels...
Displaying panels...
Panel display