cancel
Showing results for 
Search instead for 
Did you mean: 

Date Format getting Null Pointer Exception

Former Member
0 Kudos

Hi ,

I have date value in one attribute it is coming from RFC.

If I will bind the value directly to the text view ,data is getting like 10/12/2008. But whenever I am taking this value and formatting into Simple date format as October 13th,2008,I am getting "NullPointer Exception".

Code is in init() of View :

//Format Draft_Date

Date l_CreDat = wdContext.currentCtx_vn_DataElement().getCredat();

wdComponentAPI.getMessageManager().reportSuccess("Date: " + l_CreDat);

g_objDateFormat = new SimpleDateFormat("MMMM dd, yyyy");

wdContext.currentContextElement().setCtx_va_Date(g_objDateFormat.format(l_CreDat));

}catch (NullPointerException e)

{

wdComponentAPI.getMessageManager().reportException(e.toString(), true);

}

Please help me.

Thanks

Risha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Risha,

After setting the data into context attribute, bind the attribute with the context.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi ,

My problem is solved.

I am populating the nodes after that I have to set the date field in Component Controller. Next I converted date into Simple date format.Problem is solved.

Thanks for all.

Regards

Risha

Former Member
0 Kudos

Hi Risha,

Use the following code to get your required functionality

l_CreDat.toLocaleString().substring(0, 12);

You will get the output in the form Oct 14, 2008 which you require.

Hope this will help.

Thanks & Regards

Sagar Ingalwar

Former Member
0 Kudos

Hi Risha,

I had just tried your code, every thing is working fine for me, I think there might be some problem in getting the data or setting the date to Context Attribute. But your are confident on getting the date. So check the context attribute where you are setting.

I am just posing the code which i had tried. I tried with system date but it is off java.sql.date type.

try

{

long l = System.currentTimeMillis();

java.sql.Date dt = new java.sql.Date(l);

wdComponentAPI.getMessageManager().reportSuccess("Date: " + dt);

SimpleDateFormat g_objDateFormat = new SimpleDateFormat("MMMM dd, yyyy");

wdContext.currentContextElement().setAbc(g_objDateFormat.format(dt));

}

catch (NullPointerException e)

{

wdComponentAPI.getMessageManager().reportException(e.toString(), true);

}

Regards

Raghu

Former Member
0 Kudos

Hi,

Before accessing the following line make sure that the wdContext.currentCtx_vn_DataElement() is not null

if(wdContext.currentCtx_vn_DataElement() != null)

{

Date l_CreDat = wdContext.currentCtx_vn_DataElement().getCredat();

wdComponentAPI.getMessageManager().reportSuccess("Date: " + l_CreDat);

g_objDateFormat = new SimpleDateFormat("MMMM dd, yyyy");

wdContext.currentContextElement().setCtx_va_Date(g_objDateFormat.format(l_CreDat));

}catch (NullPointerException e)

{

wdComponentAPI.getMessageManager().reportException(e.toString(), true);

}

}

Regards

Ayyapparaj

Former Member
0 Kudos

Hi ,

Thank You for giving reply to all.

From RFC value is getting but if I will convert the date and setting the value by using this RFC value , the value is getting null.

what is the reason of this?

Thanks

Risha

Former Member
0 Kudos

hi!

please check the type of Date l_CreDat object whether it is java.sql.date or java.util.date.

thanks

vishal

Former Member
0 Kudos

Hi,

once check the value of "g_objDateFormat.format(l_CreDat)".

Regards,

ramesh

Edited by: Ramesh Babu V on Oct 13, 2008 10:45 AM

Edited by: Ramesh Babu V on Oct 13, 2008 10:52 AM