• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutputStream: Can you spot the Problem?

 
Karen Baog
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
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: 24213
35
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!