aspose file tools*
The moose likes Beginning Java and the fly likes cannot find constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot find constructor" Watch "cannot find constructor" New topic
Author

cannot find constructor

chop ficaro
Ranch Hand

Joined: May 02, 2010
Posts: 30
main cant find the constructor of the class on compile time. what on earth could be wrong?

DCR.java

error readout
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You've got a method named DCR that takes three float arguments, not a constructor. It's not a constructor because it's declared to return float. Constructors don't have a return type.


[Jess in Action][AskingGoodQuestions]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

As Ernest said above, new DCR(resistivity,strandingIncrement,circularMills); here you are calling the 3 argument constructor. but only you have default constructor[which is implicitly added by java compiler].
Santhosh Puttu
Greenhorn

Joined: Jun 08, 2010
Posts: 27
Use
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

@Santhosh Puttu : your code even wont compile
Santhosh Puttu
Greenhorn

Joined: Jun 08, 2010
Posts: 27
oh yes. Without creating object we cannot call non static method......
I think this should work..
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

hmm, please dont give a method name as constructor name. method name should be start with small letter.
chop ficaro
Ranch Hand

Joined: May 02, 2010
Posts: 30
Santhosh Puttu wrote:oh yes. Without creating object we cannot call non static method......
I think this should work..

thank you puttu, you code worked, but i dont undertand why. my constructor still returns a type, which i now remember is illegal thanks to the other comments. heres what i tried before your code, it didnt work, something about non static variables in a static context, but i thought it would work:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Because it's still a method. As said before, constructors don't have a return type. Your "constructor" does: float. That makes it a regular method that just happens to have the same name as the class.

Also, the resistance you're printing is the local variable, not the instance variable of your DCR instance.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
chop ficaro
Ranch Hand

Joined: May 02, 2010
Posts: 30
Rob Prime wrote:Also, the resistance you're printing is the local variable, not the instance variable of your DCR instance.

ok well why is setting the variable in main a static context?
btw main is just to test this function. this is a small part of a larger project, and i need to set the variables in another file
i want to do this the orthodox way so my code is readable, and though putt's code works, it doesnt seem orthodox. my code with the static context problem seems to make more sense to me but of coarse it doesnt work
chop ficaro
Ranch Hand

Joined: May 02, 2010
Posts: 30
solution found, thank you all very much for helping me debug my program
 
 
subject: cannot find constructor