Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find constructor

 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Santhosh Puttu : your code even wont compile
 
Santhosh Puttu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes. Without creating object we cannot call non static method......
I think this should work..
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, please dont give a method name as constructor name. method name should be start with small letter.
 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solution found, thank you all very much for helping me debug my program
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic