?
Solved

String ref

Posted on 2006-04-23
3
Medium Priority
?
220 Views
Last Modified: 2010-05-18
Not sure what is going wrong with this but I need some help figuring this out.

I have a String str = n.getNodeValue();
If I do a System.out.println(str) the program will display the information but with whitespaces and newlines
Which leads me to belive that .trim() would be the best option for this kind of thing.
The problem is, when I edit the str in any manor I get a error on that same line the edit took place.
Any idea why this might happen and or a fix for this problem?


code:
String str = n.getNodeValue();
System.out.println(str.trim());   <-----Error here (when edit takes place to str)
//System.out.pritln(str); <-------------This code would work (format looks bad)
0
Comment
Question by:no158
3 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 16522233
Hi no158,
What is the error that you get

Cheers!
0
 

Author Comment

by:no158
ID: 16522264
NullPointerException
0
 
LVL 6

Accepted Solution

by:
avinthm earned 2000 total points
ID: 16522289
Hi ,

Since str is null,   str.trim() will throw a NullPointerException

to aviod it you can do
if(str != null)
   System.out.println(str.trim())

I think System.out.println(str) prints "null"

cheers
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question