• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

OutputStream: Can you spot the Problem?

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,

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


 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic