Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

NullPointerException  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am creating a project as part of a University Assignment and all was well until i encountered a dreaded NullPointerException! I have tried all i can to work a way around it but just can't seem to suss it out. It has been causing me endless hours of frustration! If anyone could help me out then it would be HUGELY appreciated! I have included my code below and the error seems to be occuring on line 210 which reads:
if (stockCode[itemNum].equals(searchItem))
My Code
-------

[JAM -->Edited to use [CODE] and [/CODE] tags]
[ April 19, 2004: Message edited by: Joel McNary ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like your problem is in readData()
int count=0;
...
...
do
{
count++;//<---------------count is now 1, meaning stockCode[0] is null
stockCode[count] = input.readLine();
move the count++ to the end of the do/while block
 
Emile Ghazzawi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
Solved it by changing the problamatic line 210 to
CODE] if (stockCode[itemNum]!=null && stockCode[itemNum].equalsIgnoreCase(searchItem))[ [/CODE]
Also implemented your idea, much more sensible that putting it before !
Thanks for your help, i sure i'll be back asking for more very shortly!
Thanks again,
Emile
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't speak for your teacher, but where I went to school we'd lose points for not indenting. It's hard to follow your logic otherwise.
 
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that the code wasn't indented; it's that the [CODE] and [/CODE] tags were not used; thus, the indenting was not preserved. I edited the post to include them this time....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!