Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linear Search Woes

 
Marie Jeanne Thibault
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Can anyone give me a hint as to why my linear search won't work? When a number is entered in the index textfield and click the show button, that element should be displayed in the element textfield. I get all sorts of exception messages. Anything would be appreciated.
Here's the code:
//ArrayDemo.java

Thanks,
Marie
[ January 31, 2004: Message edited by: Jim Yingst ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't examine the program extremely closely, but one major problem is that there are two variables named "list": one is a member of ArrayDemo; this one is never initialized. Another is local to main(), and this one is the one that gets initialized. All the methods of ArrayDemo try to use the uninitialized one.
To fix this, you could move the code that creates the array and populates it from main() into the ArrayDemo constructor, being careful to remove the line "int[] list" that declares the local variable, so that it's the member that gets initialized instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic