This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Node Search

 
Marco Galea
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic