cancel
Showing results for 
Search instead for 
Did you mean: 

Null Pointer Exception

Former Member
0 Kudos

Hi Experts,

I have to display a smart form from R/3 to portal. I have developed a web dynpro java application to do that where a RFC adaptive model is calling the bapi that will display the smart form. The problem I am facing is that when I am deploying the application it is showing java.lang.NullPointerException error. Please guide me.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi all,

thanks for your response.

here in the application on web dynpro java, i need to display a smart form from R/3 as there login id as the input parameter in the RFC FM. below is my code:

public void wdDoInit()

  {

    //@@begin wdDoInit()

Zfm_Empform_Portal_Input input = new Zfm_Empform_Portal_Input();

                    

  Zfm_Empform_Portal_Input inputuser = new Zfm_Empform_Portal_Input();

  wdContext.nodeZfm_Empform_Portal_Input().bind(inputuser);

wdContext.currentContextElement().setPdf_data(convertXStringToURL(wdContext.currentOutputElement().getBin_File()));

    //@@end

  }

public java.lang.String convertXStringToURL( byte[] doc_content )

  {

    //@@begin convertXStringToURL()

  String url = "";

  WDWebResourceType webResType = WDWebResourceType.PDF;

  IWDWebResource webResource = WDWebResource.getWebResource(doc_content, webResType);

  try {

  url = webResource.getURL();

  } catch (WDURLException e) {

  e.printStackTrace();

  }          

  return url;

    //@@end

  }

please help me to resolve this issue.

junwu
Active Contributor
0 Kudos

which line gives u error?

Former Member
0 Kudos

Hi Jun Wu,

Thanks for your instant reply. No line is giving me any error. my code is:

public void wdDoInit()

  {

    //@@begin wdDoInit()

  Zfm_Empform_Portal_Input input = new Zfm_Empform_Portal_Input();

                    

  Zfm_Empform_Portal_Input inputuser = new Zfm_Empform_Portal_Input();

  wdContext.nodeZfm_Empform_Portal_Input().bind(inputuser);

  try

  {

  IUser user = WDClientUser.getLoggedInClientUser().getSAPUser();

  IUserAccount[] acct = user.getUserAccounts();

   

    if (acct[0] != null)

     {

  String Userid = acct[0].getLogonUid();

  wdComponentAPI.getMessageManager().reportSuccess(Userid );

  }

  }

  catch (Exception e) {

//   TODO Auto-generated catch block

  e.printStackTrace();

  }

  wdContext.currentContextElement().setPdf_data(convertXStringToURL(wdContext.currentOutputElement().getBin_File()));

    //@@end

  }

  public java.lang.String convertXStringToURL( byte[] doc_content )

  {

    //@@begin convertXStringToURL()

  String url = "";

  WDWebResourceType webResType = WDWebResourceType.PDF;

  IWDWebResource webResource = WDWebResource.getWebResource(doc_content, webResType);

  try {

  url = webResource.getURL();

  } catch (WDURLException e) {

  e.printStackTrace();

  }          

  return url;

    //@@end

  }

When I am deploying the application I am getting this error:

Please guide to resolve this issue.

junwu
Active Contributor
0 Kudos

it says line 139

Former Member
0 Kudos

Hello

The error must be coming from below line of code:

wdContext.nodeZfm_Empform_Portal_Input().bind(inputuser);


put a condition to check for node element before binding

Former Member
0 Kudos

Hi Amit,

I am not getting what are you saying. can u send me the sample code for the same?

Former Member
0 Kudos

Hi Shilpi,

When you instantiate your variable inputuser,


Zfm_Empform_Portal_Input inputuser = new Zfm_Empform_Portal_Input();

You need to pass model instance as parameter of constructor zfm_empform_portal_input class.

Refer to this document - http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/50f7192d-2808-2d10-189b-df3fa5f71...

Mahesh

govardan_raj
Contributor
0 Kudos

hi shilpi,

on seeing the error , it is specified line 139 , in your studio just goto windows- preference->java->Editor , on right side pane you check "show line number" that will diplay the line and find the code at line 139.

so that it will be easy to know at which point you are getting null pointer exception.

Regards

Govardan Raj

Former Member
0 Kudos

Hi,

I did as you have told me to do to show the line numbers so that the error Null Pointer Exception can be resolved. When I am deploying my application the RFC is passing the parameters but in my application is not able to convert the Xstring to URL that in turn will display the smart form as PDF. Below is the screen shot of the error I am getting:

Below is the screenshot of the code:

Below is the code:

public void wdDoInit()

  {

    //@@begin wdDoInit()

  wdContext.currentZfm_Empform_Portal_InputElement().setUsrid("1442");

  wdThis.wdGetZ_formController().executeZfm_Empform_Portal_Input();

  Zfm_Empform_Portal_Input input = new Zfm_Empform_Portal_Input();

    wdContext.nodeZfm_Empform_Portal_Input().bind(input);

    try {                       

    wdContext.currentZfm_Empform_Portal_InputElement().modelObject().execute();

    } catch (WDDynamicRFCExecuteException e)

    {

    e.printStackTrace();

    wdContext.currentContextElement().setPdf_data(e.getMessage());

    }

    wdContext.currentContextElement().setPdf_data(convertXStringToURL(wdContext.currentOutputElement().getBin_File()));

    //@@end

  }

public java.lang.String convertXStringToURL( byte[] doc_content )

  {

    //@@begin convertXStringToURL()

  String url = "";

  WDWebResourceType webResType = WDWebResourceType.PDF;

  IWDWebResource webResource = WDWebResource.getWebResource(doc_content, webResType);

  try {

  url = webResource.getURL();

  } catch (WDURLException e) {

  e.printStackTrace();

  }          

  return url;

    //@@end

  }

Please guide me to resolve this issue.

Former Member
0 Kudos

hi shilpi,

            why you calling bellow function..

wdThis.wdGetZ_formController().executeZfm_Empform_Portal_Input();



kindly show this function code.(executeZfm_Empform_Portal_Input();)




Regarding

antony

Former Member
0 Kudos

Few things ....

1. webresource is deprecated so instead of that use - WDResourceFactory.createCachedResource

2. Do a null check if the bytes returned is null or not.

3. If the bytes returned by RFC is null, put an external break point and check the rfc output

Mahesh

Former Member
0 Kudos

Hi Mahesh,

can you send the code how to use WDResourceFactory.createCachedResource.

Former Member
0 Kudos

IWDResource res=WDResourceFactory.createCachedResource(byte[] data, String resourceName, WDWebResourceType type);


Refer JAVA Docs for further help.


Mahesh

govardan_raj
Contributor
0 Kudos

h shilpi,

nice to see the pics with all details,

i would like to suggest a better programming style , like to use try catch block.

try

{

// All your execution code

}catch(Exception e)

{

}

in the catch block i would suggest  you to use this..

//-------------------------------------------------------------------------

StringWriter StrWriter = new StringWriter();

   Mylog.Myloc.errorT(StrWriter.toString());

   PrintWriter PntWWriter = new PrintWriter(StrWriter);

   StrWriter.getBuffer().setLength(0);

   exception.printStackTrace(PntWWriter);

   Mylog.Myloc.errorT(wdComponentAPI.getApplication().getName()+StrWriter.toString());

//--------------------------------------------------------------------------------

and at end of component controller or view controller  put this code

//@beging others

public static class Mylog

  {

 

     private static final Location Myloc = Location.getLocation("com.yourorg.MyLogController");

  }

//@end others

This will actually clearly speicify the actual cause of the error and will be logged at nwa .

in default trace.

i.e  log in as administrator to your ep server in the url

http://host:port/nwa

then go to monitoring->logs and traces-> select default trace --> here you will the find the errors that you get when you run your applications .

in the logs it will give details explaination why such error is coming .

now comign to your problem , in the above code you can see at line 123 you are getting data from node outputelement , i guess the cardinality of this is 0..n , and no element of that is available so you are getting null pointer exception.

it should be 1..1

Regards

Govardan Raj S

Answers (3)

Answers (3)

Former Member
0 Kudos

check the nwa, it will give your more detail about the error.

govardan_raj
Contributor
0 Kudos

Hi shilpi,

Can you please provide further details , like when you are deploying you are getting the null pointer error or at run time when you are using the application.

can you please post the error details completely

Regards

Govardan

junwu
Active Contributor
0 Kudos

debug first

detail error