• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

re:String buffer null pointer exception

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this program displays each character entered in the input as a seven segment digit.
For e.g, if the input is 123

The output is stored in three string buffers one for each output line. As each input digit is processed,append four characters to each buffer(three for the digit itself plus a space) For e.g., if the current digit is 9, th eprogram would append " _ " to the first buffer, " |_| " to the second buffer and " _| " to the third buffer.
I have tried the program by printing a single digit. It worked, but with multiple digits using string buffer, it gives me a null pointer exception. What am I doing wrong here?

Thanks in advance
[ December 03, 2003: Message edited by: vidu mayur ]
[Fixed overlong line in code tags - Jim]
[ December 03, 2003: Message edited by: Jim Yingst ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is polite to post the exception and stack trace. Gives those of us trying to read your code a hint as to where the problem is. In your case the problem is obvious enough. You create an array for StringBuffer objects but you don't put any StringBuffers in it. It should be getting the null pointer exception on this line:
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Vidu -
Can you make your code snipped narrower and shorter? You'll find people much more eager to help if the code is shorter and the question focused.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you make your code snipped narrower and shorter?
I fixed it. Don't put [code] tags around really long lines of text with no newlines - they don't wrap, and force the display to be really wide.
 
vidu mayur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for taking the time to read a long and wide post
When I didn't add the UBB code for the top message, it wasn't displaying my LCD numbers properly. Thanks Jim for making it narrower. Joe, that was the problem. Once I fixed it, it started working.
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic