on 05-20-2014 10:07 AM
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
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.
IWDResource res=WDResourceFactory.createCachedResource(byte[] data, String resourceName, WDWebResourceType type);
Refer JAVA Docs for further help.
Mahesh
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
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
check the nwa, it will give your more detail about the error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
debug first
detail error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.