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

NullPointerException with String  RSS feed

 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


thanks that really solved my problem
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome! Glad you got it sorted out!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!