-3

Getting nullpointer exception while invoking a method from different class

 public ArrayList<String> getSelectionTableView(String recievedToDate, String recievedFromDate) {

        ArrayList<String> response = new ArrayList<String>();
        SelectionTable sobj = null;
        response= sobj.selectionTableValue(recievedToDate, recievedFromDate);
        return response;
}

In this SelectionTable class is just making a JDBC connection and processing a Select query and returning the result in an array list. SelectionTable class is working fine(I have tested it separately ). I am getting nullpointer exception in method call. While debugging ,as the iteration reaches the method call, it is getting directed to below java method:

public InvocationTargetException(Throwable target) {
    super((Throwable)null);  // Disallow initCause
    this.target = target;
}

and I am getting below Errors:

com.iti.gwtproject.pcmaintenancelog.client.service.CustomService.getSelectionTableView(java.lang.String,java.lang.String)' threw an unexpected exception: java.lang.NullPointerException

FYI: getSelectionTableView method is getting invoked by a RPC call.

  • on line 4 you set `sobj` to null, so invoking a method on it always throws a `NPE` – Lino Jul 26 '17 at 08:07
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Tom Jul 26 '17 at 08:17

2 Answers2

1
    SelectionTable sobj = null;
    response= sobj.selectionTableValue(recievedToDate, recievedFromDate);

There you go. sobj is always null when you try to call selectionTableValue on it...

Mark
  • 1,498
  • 1
  • 9
  • 13
0

As Mark mentioned:

SelectionTable sobj = null;

So the object will always be null when u call the selectionTableValue on the sobjobject.

Maybe you could try making a constructor in the SelectionTable to initialize a null object.

Or maybe a noob solution, you dont require that statement at all. xD

saurabh gupta
  • 520
  • 1
  • 4
  • 11
  • even if I am removing SelectionTable sobj = null; and calling cunstructor of SelectionTable I am facing same problem.Now edited code is : [response= selectionTableobj.SelectionTable(recievedToDate, recievedFromDate);] – srijita kushwaha Jul 26 '17 at 09:00