0

i have the code below in my java class .

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webservice;

import java.util.Iterator;
import java.util.List;


public class Webservice {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        ArrayOfString aar = new ArrayOfString();
        aar.getString().add("1025976002");
        aar.getString().add("1026020904");
        aar.getString().add("1026020704");
        aar.getString().add("1026026201");
        aar.getString().add("1026036901");
        aar.getString().add("");
        ArrayOfStatusContainer status = getStatusList(aar);
        List<StatusContainer> li =  status.getStatusContainer(); 
       Iterator litr=li.listIterator();    
      // System.out.println("Elements in forward directiton");   
       while(litr.hasNext()){  
           StatusContainer test = (StatusContainer)litr.next();
          System.out.println(test.getStatus());       
       } 

    }

    private static ArrayOfStatusContainer getStatusList(webservice.ArrayOfString keys) {
        webservice.AdStatusWS service = new webservice.AdStatusWS();
        webservice.AdStatusWSSoap port = service.getAdStatusWSSoap();
        return port.getStatusList(keys);

    }
}

When ever i enter an empty string or enter a duplicate string value i get a nullpointer exception. I have been trying for a while, but i found no solution so far. I have attached a screen shot of the exception below. Stack trace is below:

Sent
Booked
Multiple Errors
Exception in thread "main" java.lang.NullPointerException
In QC
Need correction client
    at webservice.Webservice.main(Webservice.java:34)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

enter image description here

13
  • 2
    Use a debugger, step through you code, identify where the null reference is coming from and correct it if it is invalid. Commented Oct 11, 2013 at 15:06
  • 2
    What is this, debugging for ants? Commented Oct 11, 2013 at 15:07
  • 1
    We see the stack trace. We just can't read it. Because we're not ants. Commented Oct 11, 2013 at 15:09
  • 1
    @nhgrif right click--> open image in new tab--> click it on. That is in Chrome. If firefox, rightclick--> view image Commented Oct 11, 2013 at 15:11
  • 1
    @sᴜʀᴇsʜᴀᴛᴛᴀ All right, well I learned something new then. But it's more helpful if the poster just types out the exception as well as pointing us directly to the line it refers to. Commented Oct 11, 2013 at 15:12

2 Answers 2

3

The Console says that the nullpointer exception was throw in line 34, what's possible means that test variable is null and you're trying to access a property of an object null validate null first.

 while(litr.hasNext()){  
       StatusContainer test = (StatusContainer)litr.next();
      if(test != null)
          System.out.println(test.getStatus());       
  } 
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure that you always add null checks before accessing a properties from object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.