| | |
Cannot find symbol
![]() |
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
Can't you have a setter method. For example...
Complex.java
Pedantic.java
Complex.java
Java Syntax (Toggle Plain Text)
/* * Complex.java * * Created on 30 April 2006, 17:37 */ public class Complex { private double imaginary; private double real; /** @ Setter method * */ public void Set(double x, double y) { real = x; imaginary = y; } public void print() { System.out.println(real+" + "+imaginary+"i"); } }
Pedantic.java
Java Syntax (Toggle Plain Text)
/* * * * Created on 29 April 2006, 17:07 */ class Pedantic { public static void main (String [] args) { Complex a = new Complex(); a.Set(9.3,2.4); a.print(); } }
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
I think the problem is that :
is not a constructor. A constructor does not have a return type, and yes, even void is a return type.
Change to :
and it should work, i think :cheesy:
Java Syntax (Toggle Plain Text)
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 :
Java Syntax (Toggle Plain Text)
public Complex(double x, double y)
and it should work, i think :cheesy:
:?: Sometimes i wonder if i'm on the right planet :!:
![]() |
Similar Threads
- connot find symbol symbol class (Java)
- Cannot find symbol, Constructor... (Java)
- Another "cannot find symbol" compiling error (Java)
- Cannot resolve symbol (Java)
- I've tried everything...setting font of selected text (Java)
- package org.jdom.* does not exist (Java)
Other Threads in the Java Forum
- Previous Thread: java programming language
- Next Thread: JFrame GUI Problem
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list mac main map method methods mobile myregfun netbeans notdisplaying number online printf problem program project qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






