my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Node Search Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Node Search" Watch "Node Search" New topic
Author

Node Search

Marco Galea
Ranch Hand

Joined: Mar 30, 2011
Posts: 30
Hi there, i have a problem when trying to search a particular node whilst using a keyword.... The result is always to null and im suspecting that im not actually pointing to the object in the node but just the position. Would appreciate any suggestions please. Attaching code and sry if there;s quite a bit there......

Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
I suspect one problem is that your search function tests for equality between two strings using the "==" operator; in order to see if two different strings have the same value, use string1.equals(string2), or string1.equalsIgnoreCase(string2)

There are other possible problems with your code, but I would definitely change that.

I would also suggest that you learn to use a debugger; you can set a "breakpoint" at a line, meaning that execution stops at that line and allows you to view the values of variables. Experience will suggest where to set breakpoints to speed up the debugging process, in the meanwhile you'll get some insight into what's really happening. In this case, once you had stepped through the line temp.obj.Surname == keyword and seen that the values were the same but it didn't match in that test, then your question would become very specific: Why doesn't temp.obj.Surname == keyword return true? The more specific questions are easier to answer, and you will be able to answer more of them yourself as you do more programming.

Good luck.
Marco Galea
Ranch Hand

Joined: Mar 30, 2011
Posts: 30
Thanks Ralph for the time taken to review my code. You were right regarding the equality operator and i used the one suggested by yourself string1.equals(string2) and i got a good result.
Will def search about using breakpoints aswell, didnt actually know about them.
Thanks again
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Welcome to the Ranch
That if (something == 's' || something == 'S') ... block looks a good candidate for conversion to a switch-case block.
Marco Galea
Ranch Hand

Joined: Mar 30, 2011
Posts: 30
Thanks. very good and fast feedback, keep it up guys ......
Campbell Ritchie wrote:Welcome to the Ranch
That if (something == 's' || something == 'S') ... block looks a good candidate for conversion to a switch-case block.

In fact im playing around with the code to try to minimize lines and make it look a little more decent
 
Consider Paul's rocket mass heater.
 
subject: Node Search