Re: Cannot find symbol error
Hmmmm...not sure why it couldn't find Account class itself. Can say that you should have something like
Code java:
public class Account{
private double balance;
public Account(double initBalance){
setBalance(initBalance);
}
public void setBalance(double initBalance)
{
this.balance = initBalance;
}
public double getBalance()
{
return balance;
}
}
Code java:
public class AccountTest{
public static void main(String[] args){
Account acct = new Account(100.0);
acct.setBalance(acct.getBalance()+ 47.0) ;
acct.setBalance(acct.getBalance() - 150.0) ;
System.out.println("final account balance is: "+acct.getBalance());
}
}
See if the problem still is there.
If it still is mad, put both classes in the same package.
If it still won't work after that, I don't know what to say.
It works now.
Re: Cannot find symbol error
javapenguin: You posted code that doesn't compile. Why do you insist on continuing to do this?
OP: The code you posted compiles just fine for me. Compiling AccountTest.java alone should do all the required work. Not sure what your problem is. I copied and pasted the code you posted into two files in the same dir, and they compiled just fine. Obviously this isn't that helpful, since it isn't working for you, but we probably need more info. Post the commands you are running to compile (along with the prompt that shows what directory you are running these from), as well as a directory listing.
Re: Cannot find symbol error
Quote:
Originally Posted by
DavidFongs
javapenguin: You posted code that doesn't compile. Why do you insist on continuing to do this?
OP: The code you posted compiles just fine for me. Compiling AccountTest.java alone should do all the required work. Not sure what your problem is. I copied and pasted the code you posted into two files in the same dir, and they compiled just fine. Obviously this isn't that helpful, since it isn't working for you, but we probably need more info. Post the commands you are running to compile (along with the prompt that shows what directory you are running these from), as well as a directory listing.
It doesn't?
Let me check it out.
#-o#-o#-o#-o#-o#-o
I put doube instead of double once.
And I forgot to put a value in the set Balance. That was probably a result of being very tired and frustrated from doing a lot of homework.
Mistakes happen.
Have corrected it.
Code java:
public class Account{
private double balance;
public Account(double initBalance){
setBalance(initBalance);
}
public void setBalance(double initBalance)
{
this.balance = initBalance;
}
public double getBalance()
{
return balance;
}
}
Code java:
public class AccountTest{
public static void main(String[] args){
Account acct = new Account(100.0);
acct.setBalance(acct.getBalance()+ 47.0);
acct.setBalance(acct.getBalance() - 150.0) ;
System.out.println("final account balance is: "+acct.getBalance());
}
}
final account balance is: -3.0
Re: Cannot find symbol error
Quote:
Originally Posted by
DavidFongs
javapenguin: You posted code that doesn't compile. Why do you insist on continuing to do this?
OP: The code you posted compiles just fine for me. Compiling AccountTest.java alone should do all the required work. Not sure what your problem is. I copied and pasted the code you posted into two files in the same dir, and they compiled just fine. Obviously this isn't that helpful, since it isn't working for you, but we probably need more info. Post the commands you are running to compile (along with the prompt that shows what directory you are running these from), as well as a directory listing.
As the OP does appear to have the directories.
It says they're both on the D Drive and should be able to be seen by each other.
I had recommended putting both in same package if it still wouldn't compile.
Re: Cannot find symbol error
Please test any code before posting it as a solution. Incorrect code leads to more confusion!
Re: Cannot find symbol error
Quote:
Originally Posted by
javapenguin
It doesn't?
Let me check it out.
I put doube instead of double once.
And I forgot to put a value in the set Balance. That was probably a result of being very tired and frustrated from doing a lot of homework.
Mistakes happen.
Have corrected it.
That, and you also had assignment errors.
While you are right that mistakes do happen, they don't happen if you TRY it first. Which is incredibly simple to do. Instead, by being lazy, you are posting code that likely leads to more confusion than it does good for the OP. Weren't you banned for this once already? You would think you would learn your lesson. In this case it is as easy as saving the two classes, and typing "javac AccountTest.java"
Re: Cannot find symbol error
Thanks to everyone for trying to help me with this!! But I found out that the problem was not in my code, but in my classpath setting for some weird reason!! Originally my classpath was as follows:
Classpath = C:\Program Files\Java\jdk1.6.0_23\bin;
Now I've set it to:
Classpath = .;C:\Program Files\Java\jdk1.6.0_23\bin;
Am not sure why I need the ".;" in front of the path itself, I did it only cos I was told to and it solved my problem! Can some one explain why that works? Am not sure if I making my question clear, please feel free to ask me to elaborate further.
Thanks once again!!!
Anu
Re: Cannot find symbol error
the .; tells the java compiler to also search in the current directory (actually, only the . tells it to search in the current directory, the ; allows you to let it search in multiple directories separated by ;).
Re: Cannot find symbol error
Thanks a lot!! Once again to everyone for helping me with this and explaining the classpath issue to me.
Anu