• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Linear Search Woes  RSS feed

Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
author and iconoclast
Posts: 24220
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!