• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

OutputStream: Can you spot the Problem?  RSS feed

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

What is the problem in this code?
It doesn't print the string "Send Mesage" (located) in main(), although it successfully opens the SerialPort and gets the OutputStream.
Even if I put lines A and B (in bold) in a while(true) loop, the application still terminates (and not still print the "Send Message"), even though I would have thought it will just indefinitely loop.


[ August 05, 2005: Message edited by: Karen Baog ]
[ August 05, 2005: Message edited by: Karen Baog ]
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


AAAAAAAAAAAAAAAAAARGHHHHHHHHHHH!

Here Java is handing you a nice explanation, and you are dropping it on the floor with the peanut shells. At least have an e.printStackTrace() in there -- I guarantee it will tell you something useful about what's going wrong.
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It reports java.lang.NullPointerException, which is reported by the send() method.

Please tell me how to fix it.

Karen
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

The data passed to the .write() method is definitely not null. So, I really am at a loss here why it would throw a NullPointerException error.

Karen
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now you're getting somewhere -- you know something is null, and you know it's something involved in one specific line of code. There are two variables dereferenced on that line. Ask yourself -- very carefully -- if either of the variables on that line might be null. Even if you think they can't, trace through the program and make sure you can point to the place where each variable used on that line is initialized. I guarantee, again, that you will learn something interesting -- in fact, this time you'll find the problem.
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't figure out why the outputStream could not be initialized. I've even put this line in the setup() method, but still hits this NullPointerException.

More
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I know the outputStream is not initialized.
I've been googling the web and can't find any example how this is initialized. The example that came with the comm API is not initialized either.

Still
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

Finally, I traced it!
I persisted, thanks for your encouragement!


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!