String ref

Posted on 2006-04-23
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?

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)
Question by:no158
    LVL 10

    Expert Comment

    Hi no158,
    What is the error that you get


    Author Comment

    LVL 6

    Accepted Solution

    Hi ,

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

    to aviod it you can do
    if(str != null)

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Title # Comments Views Activity
    Multiple issues with Java 14 37
    Automated mobile software testing 8 106
    copyEvens challenge 6 46
    bigHeights  challenge 13 43
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now