Cannot find symbol

Reply

Join Date: Apr 2006
Posts: 4
Reputation: K.Duncan is an unknown quantity at this point 
Solved Threads: 0
K.Duncan K.Duncan is offline Offline
Newbie Poster

Cannot find symbol

 
0
  #1
Apr 30th, 2006
I'm working on a fairly basic program and can not seem to get it to work. I've checked my spelling and all that; the only thing I can think of is my main isn't able to find my class file.

Here's the error message:

ComplexDemo.java:10: cannot find symbol
symbol : constructor Complex(double,double)
location: class Complex
Complex a=new Complex(9.9, 7.7);
^

And the constructor in the class file:

public void Complex(double x, double y)
{
real=x;
imaginary=y;
}

When I remove the values it works fine but that sort of defeats the purpose. Any suggestions?

-Kai
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Cannot find symbol

 
0
  #2
Apr 30th, 2006
Can't you have a setter method. For example...

Complex.java
  1. /*
  2.  * Complex.java
  3.  *
  4.  * Created on 30 April 2006, 17:37
  5.  */
  6.  
  7.  
  8. public class Complex {
  9. private double imaginary;
  10. private double real;
  11.  
  12. /** @ Setter method
  13.   *
  14.   */
  15. public void Set(double x, double y)
  16. {
  17. real = x;
  18. imaginary = y;
  19. }
  20.  
  21. public void print()
  22. {
  23. System.out.println(real+" + "+imaginary+"i");
  24. }
  25.  
  26.  
  27. }


Pedantic.java
  1. /*
  2.  *
  3.  *
  4.  * Created on 29 April 2006, 17:07
  5.  */
  6.  
  7. class Pedantic {
  8.  
  9. public static void main (String [] args) {
  10.  
  11. Complex a = new Complex();
  12. a.Set(9.3,2.4);
  13. a.print();
  14.  
  15.  
  16. }
  17.  
  18. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: K.Duncan is an unknown quantity at this point 
Solved Threads: 0
K.Duncan K.Duncan is offline Offline
Newbie Poster

Re: Cannot find symbol

 
0
  #3
Apr 30th, 2006
That does work, but I'm more concerned as to why the method I used doesn't. Also, while I'm not positive, I think what I need to do requires initializing with the values. Thank you for the help.

-Kai
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Cannot find symbol

 
0
  #4
Apr 30th, 2006
You could probably get it to work using your way, but I don't like how it would read.

I dunno???

Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: K.Duncan is an unknown quantity at this point 
Solved Threads: 0
K.Duncan K.Duncan is offline Offline
Newbie Poster

Re: Cannot find symbol

 
0
  #5
Apr 30th, 2006
Well, the set works at the very least, no complaints there. I do have one more little glitch in this thing however.

I've got two classes, Addition and Subtraction, designed to receive two Complex objects and return one. In my program I've got this written;

d=Addition(a,b);

That nets me a 'cannot find symbol' error. Any ideas? And thanks again for the help, I greatly appreciate it.

-Kai
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: K.Duncan is an unknown quantity at this point 
Solved Threads: 0
K.Duncan K.Duncan is offline Offline
Newbie Poster

Re: Cannot find symbol

 
0
  #6
Apr 30th, 2006
Ah, nevermind. Changed it to d=d.Addition(a, b) and everything worked out. Guess that's what I get for missing about two weeks of classes.

-Kai
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 27
Reputation: DeepZ is an unknown quantity at this point 
Solved Threads: 0
DeepZ's Avatar
DeepZ DeepZ is offline Offline
Light Poster

Re: Cannot find symbol

 
0
  #7
May 3rd, 2006
I think the problem is that :
  1. public void Complex(double x, double y)

is not a constructor. A constructor does not have a return type, and yes, even void is a return type.

Change to :
  1. public Complex(double x, double y)

and it should work, i think :cheesy:
:?: Sometimes i wonder if i'm on the right planet :!:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC