I'm going a bit mad trying to find out what is wrong with my code and I'd be grateful for any help.
Basically, I have a little program that should test my French vocabulary. I have got a list of vocab in an sql database. I retrieve this vocab and turn it into an ArrayList of VocabElement objects These objects basically have two instance variables, one string for the english and one for the french.
As each word comes to be tested I assign one to a private instance variable (String) in my VocabTester class called currentWord and the other to a private instance variable (String) called currentTargetWord.
I display one and then I should type in the answer and hit the submit button and as you can see from the code below, the currentTargetWord string should be compared with whatever has been typed into the answerTextField and if it's the right answer then I'm a linguistic genius!
Only problem is that even when I have the answer right (and believe me I have typed it exactly right) the program tells me I've got the wrong answer. I've put in a couple of println statements to see if the currentTargetWord and answer String are the same at that point of the program and they are!! So surely when the next statement says
the next block of code should run, shouldn't it? Does it make any difference that answer is a local variable and currentTargerWord is an instance variable or that currentTargetWord is private?
Good question. To really understand why you are having this problem, check out this page. There is a way to compare string values, which is what you want to do. But what you are doing here is comparing string OBJECTS. They have the same value but are different objects, and that's why your program says they are not equal.
Studying for SCJP 6
Joined: Oct 24, 2008
Thanks so much for the info. It's just what I needed. (As I'm sure you knew).
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com