File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Linear Search Woes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Linear Search Woes" Watch "Linear Search Woes" New topic

Linear Search Woes

Marie Jeanne Thibault

Joined: Nov 15, 2003
Posts: 15
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:

[ January 31, 2004: Message edited by: Jim Yingst ]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Linear Search Woes
It's not a secret anymore!