Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with button & ByteArrayOutputSream  RSS feed

 
sa burch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the button in MenuButtonHandler to send a byte through a ByteOutputStream into the method buttonConnect that it calls. The button seems to generate an ASCII string, but I get a null pointer exception when buttonConnect is invoked -- the string is not being read into byte z[]. Can someone tell me why? thanks



 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as i can see, the stream you are writing to in actionPerformed method and buttonConnect are different.

I don't know whether this code compiles but if it does then i think you have an instance field asciiStream but in actionPerformed() you are creating a local variable with the same name. So, any changes made to this local variable will not affect the instance level stream.
 
sa burch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! How can I make sure I am calling the same stream?
 
sa burch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I forgot to mention that it compiles.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sa burch:
Thanks! How can I make sure I am calling the same stream?


Instead of creating a local variable initialize the instance variable!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!