aravindhit / google-voice-java

Automatically exported from code.google.com/p/google-voice-java
0 stars 0 forks source link

Null Pointer Exception Error Parsing Contact #57

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In an Android application, I get the following error:

java.lang.NullPointerException
at com.techventus.server.voice.util.SMSParser.parseContact(SMSParser.java:143)
at com.techventus.server.voice.util.SMSParser.getSMSThreads(SMSParser.java:115)
at com.techventus.server.voice.Voice.getSMSThreads(Voice.java:842)

Original issue reported on code.google.com by cs3vi...@gmail.com on 8 Nov 2013 at 2:29

GoogleCodeExporter commented 9 years ago
Here is the fix. You can't call .trim() on a text element until you check if 
it's null or not:

    /**
     * Parses the contact information from the DOM Element.
     * 
     * @param element
     *            the DOM Element
     * @return the Contact
     */
    private Contact parseContact(Element element) {
        String name = element.selectSingleNode(XPathQuery.MESSAGE_NAME_LINK).getText();
        if(name != null){
            name = name.trim();
        }

Original comment by cs3vi...@gmail.com on 8 Nov 2013 at 2:48