cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.NullPointerException after binding web service model

0 Kudos

Hello, I was trying to make a web dynpro that use a web to display data, but after I do the binding in the DoInit of the model controller I got a error when I run the dynpro.

this is the error:

java.lang.NullPointerException

at com.sap.tc.webdynpro.model.webservice.base.model.BaseGenericModelClass.retrieveTargetRoleInfo(BaseGenericModelClass.java:91)

at com.sap.tc.webdynpro.model.webservice.base.model.BaseGenericModelClass.getRelatedModelObject(BaseGenericModelClass.java:388)

at com.sap.tc.webdynpro.model.webservice.gci.WSTypedModelClass.getRelatedModelObject(WSTypedModelClass.java:65)

at com.muck.demos.wsdemo3.model.BAPI_FLIGHT_GETLIST_Request.getDESTINATION_FROM(BAPI_FLIGHT_GETLIST_Request.java:60)

at com.muck.demos.wsdemo3.wdp.IPublicWSDemo3$IDESTINATION_FROMNode.doSupplyElements(IPublicWSDemo3.java:880)

This is the component controller context [http://img194.imageshack.us/img194/2293/componentcontroller.png]

the search view context [http://img193.imageshack.us/img193/5646/searchview.png]

and the results view context [http://img299.imageshack.us/img299/4567/resultsview.png]

finaly this is the code:


  public void wdDoInit()
  {
  
    FlightData model = new FlightData(); 
    Request_BAPI_FLIGHT_GETLIST list = new Request_BAPI_FLIGHT_GETLIST(model);
    BAPI_FLIGHT_GETLIST_Request request = new BAPI_FLIGHT_GETLIST_Request(model);
    list.setBAPI_FLIGHT_GETLIST(request);
    wdContext.nodeRequest_BAPI_FLIGHT_GETLIST().bind(list);
  
 } 

I hope that someone can help me, thank you.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

I assume that this code is in Component controller or view controller. In case you want the elements to populate data from view then these two lines should suffice. I dont understand why you need to model instance and bind it.

Request_BAPI_FLIGHT_GETLIST list = new Request_BAPI_FLIGHT_GETLIST();

wdContext.nodeRequest_BAPI_FLIGHT_GETLIST().bind(list);

Regards

Srini

0 Kudos

That doesn't work either, if I put those lines in wdDoInit of the component controller the dynpro shows up, but the input field for the search is disabled, anyway I clicked the search button and this is the response I got 😕

com.sap.tc.webdynpro.model.webservice.base.exception.BaseModelRuntimeException: No object for mandatory target role 'FLIGHT_LIST' of model class 'BAPI_FLIGHT_GETLIST_Response' with cardinality 'ONE' maintained

at com.sap.tc.webdynpro.model.webservice.base.model.BaseGenericModelClass.getRelatedModelObject(BaseGenericModelClass.java:392)

at com.sap.tc.webdynpro.model.webservice.gci.WSTypedModelClass.getRelatedModelObject(WSTypedModelClass.java:65)

at com.muck.demos.wsdemo3.model.BAPI_FLIGHT_GETLIST_Response.getFLIGHT_LIST(BAPI_FLIGHT_GETLIST_Response.java:88)

at com.muck.demos.wsdemo3.wdp.IPublicWSDemo3$IFLIGHT_LISTNode.doSupplyElements(IPublicWSDemo3.java:1668)

at com.sap.tc.webdynpro.progmodel.context.DataNode.supplyElements(DataNode.java:100)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Rafael,

Check the cardinality of the nodes. Should set it to 0..n.

Thanks

Avik

former_member192434
Active Contributor
0 Kudos

Hi

Are you useing NWDS(CE 7.1) then you have use this sort of code to bind it

Model1 model1Model = new Model1();
    Bapi_Flight_Getlist_Input bapi_Flight_Getlist_Input = new Bapi_Flight_Getlist_Input(model1Model);
    Bapi_Flight_Getlist_Output output = new Bapi_Flight_Getlist_Output(model1Model);
    java.util.List<Bapisfldat> flight_List = new ArrayList<Bapisfldat>();
    output.setFlight_List(flight_List);
    wdContext.nodeBapi_Flight_Getlist_Input().bind(bapi_Flight_Getlist_Input);

and if you are using NWD 7.0 then the binding will be differ use below sample code to bind it.

Bapi_Flight_Getlist_Input input = new Bapi_Flight_Getlist_Input();
     input.setDestination_From(new Bapisfldst());
     input.setDestination_To( new Bapisfldst());
     wdContext.nodeBapi_Flight_Getlist_Input().bind(input);

PS: Also check the cardinality should be 1..n not 0:n.

Thanks

0 Kudos

Hello Anup,

I'm using CE 7.1 I tried your code but I got this error:

java.lang.Error: Unresolved compilation problem: The method setFLIGHT_LIST(FLIGHT_LIST) in the type BAPI_FLIGHT_GETLIST_Response is not applicable for the arguments (List<BAPISFLDAT>)

Due to this lines of code:

java.util.List<BAPISFLDAT> flight_List = new java.util.ArrayList<BAPISFLDAT>();
    output.setFLIGHT_LIST(flight_List);

Regarding the cardinalities this is what I have set:

[http://img220.imageshack.us/img220/5528/cardinality.png]

They are all at the maximum relation available, where it says 1..1 is because there is not 1..n.

Thank you.

Former Member
0 Kudos

Hi,

I dont think you can directly set the List to Output class.

I had done this earlier. I remember there should be a complex data type class by name TableofBAPISFLDAT. You need to

instantiate it and then for this you need to set the list finally the complex type to output class like the following code.

TableofBAPISFLDAT flighttable = new TableofBAPISFLDAT(model1Model);     // Complex type
java.util.List<BAPISFLDAT> flight_List = new java.util.ArrayList<BAPISFLDAT>();  //simple type
flighttable.add(flight_List);   //add simple type to complex type such that it holds 1..n property
    output.setFLIGHT_LIST(flighttable);  // now set the complex type to output node

Hope this will solve your problem

Regards

Raghu

former_member197348
Active Contributor
0 Kudos

Hi Rafael Esteban,

Try this:

FlightData  flightModel = new FlightData ();
    Request_BAPI_FLIGHT_GETLIST list  = new Request_BAPI_FLIGHT_GETLIST(flightModel);
    BAPI_FLIGHT_GETLIST flightGetList = new BAPI_FLIGHT_GETLIST(flightModel);
    list.setBAPI_FLIGHT_GETLIST(flightGetList);
//Try to add TableOfbapisfldat  item as well    
TableOfbapisfldat flightList = new TableOfbapisfldat(flightModel);
     java.util.List<Bapisfldat> item = new ArrayList<Bapisfldat>();
    flightList.setItem(item);

    wdContext.node Request_BAPI_FLIGHT_GETLIST().bind(list);

Please revert back if this does not solve your problem.

Please reset the cardinality to default value if you have changed anything

Regards,

Siva

0 Kudos

Hello Raghu and Siva

I was trying your suggestions but immediately I got this new error "TableOfBAPISFLDAT cannot be resolved to a type" how do I create this type of data?? I really don't know much about java I'm an ABAP developer learning about this.

Thank you.

former_member197348
Active Contributor
0 Kudos

Hi Rafael Esteban,

It is not a big problem.

Even if you are ABAP developer you can do it easily. Just in beginning you may face little difficult.

Simply Click CtrlShiftO or right click -> Organize Imports . The error will go.

Still the error remains just comment

//TableOfbapisfldat flightList = new TableOfbapisfldat(flightModel);
 //    java.util.List<Bapisfldat> item = new ArrayList<Bapisfldat>();
  //  flightList.setItem(item);

and try.

Regards,

Siva