• Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerException in JSP  RSS feed

 
Robert Campbell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make a JSP that uses Xor to encode and decode. Right now whenever I try to run my JSP I get an exception at line 38: . My whole code is as follows:


My JSP page is:

The radio buttons don't have any impact yet.
 
Robert Campbell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just realized the line number I gave is wrong, my apologies. The error occurs in line 31.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either text or key is null at that point. Don't use set methods to set those fields. Set them in the constructor, then you know the object is always in a consistent state.

Don't use += or similar for Strings.
Use a StringBuilder and append. The return the output of the StringBuilder's toString method.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check with your XOR method that there is no chance of ever getting 0x0004 or 0x001a (ctrl‑D and ctrl‑Z). If you print those characters you may have problems with them representing end of file. I may be mistaken on that point.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a Linux box you don't seem to have any problems: I tried it and got 0004/001A in little boxes. Don't know whether you would have any problems on Windows.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But beware if you ever get (char)0x0007 (=ctrl-G)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!