The moose likes I/O and Streams and the fly likes NullPointerException with String Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "NullPointerException with String" Watch "NullPointerException with String" New topic
Author

NullPointerException with String

debraj mallick
Ranch Hand

Joined: Mar 08, 2011
Posts: 180

hi all,

my code is like

the exception which i am getting is

all i need is to print the entire string.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3133
Of course this line:

is giving you NPE. You know that myHtml is null, because otherwise you would not have gotten out of the loop. So of course myHtml.toString() must give NPE.

debraj mallick wrote:
all i need is to print the entire string.


You mean the full HTML that you read in the loop? And you want to print the whole thing out after the loop exits? Then you have to build up a string or other data structure that holds the whole thing. Right now, your loop says:


Inside the loop you could use StringBuilder.append(), or, if you still need access to the individual lines, java.util.List.add().
debraj mallick
Ranch Hand

Joined: Mar 08, 2011
Posts: 180



thanks that really solved my problem
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3133
You're very welcome! Glad you got it sorted out!
 
 
subject: NullPointerException with String
 
Threads others viewed
Problem reading a file
output in a file
Unable to invoke servlet from client (simple java class)
how to extract search engine results
Efficient way to download an image
IntelliJ Java IDE