- #1
doug5289
- 12
- 0
Homework Statement
Why am I getting an error message "Cannot find symbol"
Color myColor = new Color(255, 200, 150);
doug5289 said:I am trying to fill a rectangle and no matter what I put it doesn't fill it up. Any idea's?
g.fillRect(10, 10, 80, 30);
Mark44 said:LOL! Great minds think alike.
You should put [ code] and [ /code] tags (without leading spaces) around your code. I have done this below.doug5289 said:I am getting this error while compiling this: Any help would sure be welcomed. I am in my first year and never dreamed it could be this hard.
E:\RistDouglas_DoubleMyNumberTester.java:21: cannot find symbol
symbol : constructor RistDouglas_DoubleMyNumber(int)
location: class RistDouglas_DoubleMyNumber
aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber(num);
^
doug5289 said:Code:public class LastNameFirstName_DoubleMyNumberTester { //Class Non-Accessor/Non-Mutator Method public static void main (String[] args) { //Method's Local Variables int num, doubleNum; int DoubleMyNumber,aDoubleMyNumberObject; //Method's Statements //Display the purpose of the program. System.out.println("This program will take a programmer-defined " + "number and double it."); System.out.println(); //Prints a blank line. //Initialize the number. num = 7; //Construct the object. aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber(); //Double the number. RistDouglas_DoubleMyNumber.doubleIt(); //Get the result. doubleNum = aDoubleMyNumberObject.getNumber(); //Display results. System.out.println("The result of doubling the number " + doubleNum + " is " + num + "."); System.out.println(); //Prints a blank line.
public class LastNameFirstName_DoubleMyNumberTester
{
//Class Non-Accessor/Non-Mutator Method
public static void main (String[] args)
{
//Method's Local Variables
int num, doubleNum;
int DoubleMyNumber,aDoubleMyNumberObject;
//Method's Statements
//Display the purpose of the program.
System.out.println("This program will take a programmer-defined " +
"number and double it.");
System.out.println(); //Prints a blank line.
//Initialize the number.
num = 7;
//Construct the object.
aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber();
//Double the number.
RistDouglas_DoubleMyNumber.doubleIt();
//Get the result.
doubleNum = aDoubleMyNumberObject.getNumber();
//Display results.
System.out.println("The result of doubling the number " + doubleNum +
" is " + num + ".");
System.out.println(); //Prints a blank line.
// Mark44: no more code was shown.
}
}
public class RistDouglas_DoubleMyNumber
{
//Instance Variables
private int num, myNumber;
//Instance Constructor
public RistDouglas_DoubleMyNumber()
{
this.num = myNumber;
}
//Instance Mutator Method
public void setDouble(int doubleIt)
{
this.myNumber = myNumber * 2;
}
//Instance Accessor Method
public int getNumber()
{
return this.num;
}
}
aDoubleMyNumberObject = new RistDouglas_DoubleMyNumber();
RistDouglas_DoubleMyNumber numberObject = new RistDouglas_DoubleMyNumber(num);
public class RistDouglas_DoubleMyNumber
{
//Instance Variables
private int num, myNumber;
//Instance Constructor
public RistDouglas_DoubleMyNumber()
{
this.num = myNumber;
}
//Instance Mutator Method
public void setDouble(int doubleIt)
{
this.myNumber = myNumber * 2;
}
//Instance Accessor Method
public int getNumber()
{
return this.num;
}
}
The "Cannot find symbol" error in Java means that the compiler is unable to locate a variable, method, or class that has been referenced in the code. This could be due to a misspelled identifier, a missing import statement, or a scope issue.
To fix the "Cannot find symbol" error, you should first check for any spelling errors in your code. Next, make sure that the referenced identifier is declared and initialized in the correct scope. If the identifier is from an external class, make sure to import it properly. If all else fails, try restarting your IDE or clearing the cache.
If the code used to work but is now showing a "Cannot find symbol" error, it is likely that the referenced identifier has been changed or removed. Check for any recent changes in the code or external libraries that could have caused this error.
No, a missing semicolon would result in a different error. The "Cannot find symbol" error specifically refers to the inability to locate an identifier in the code.
To prevent "Cannot find symbol" errors, it is important to carefully check for any spelling errors and ensure that all identifiers are properly declared and initialized. It is also helpful to regularly test and debug your code to catch any potential errors early on.