PDA

View Full Version : NullPointerException in TimeField::getValue()::getDate()



rezdm
18 Jan 2012, 5:58 AM
Hello.

I've got the following issue(?) in 2.2.3:


public class SomePanel extends ContentPanel
{
private final TimeField theFieldTimeStart = new TimeField();
private final DateTimeFormat theTimeFieldsDateFormat = DateTimeFormat.getFormat("HH:mm");
public SomePanel()
{
theFieldTimeStart.setTriggerAction(ComboBox.TriggerAction.ALL);
theFieldTimeStart.setFormat(theTimeFieldsDateFormat);
}

@Override protected void onRender(Element aParent, int aPos)
{
super.onRender(aParent, aPos);
final Time myTimeStart = new Time();
myTimeStart.setText("09:00");
theFieldTimeStart.setValue(myTimeStart);
}

private void handleSomeEvent()
{
//Here I need to get Date from theFieldTimeStart
theFieldTimeStart.getValue().getDate(); //causes NPE
theFieldTimeStart.getDateValue(); //causes NPE
//my workaround:
final Date myDateStart = theTimeFieldsDateFormat.parse(theFieldTimeStart.getValue().getText());
}
}



Is it supposed behavior or I missed a step in initialization?


Thanks.

sven
18 Jan 2012, 3:17 PM
Who is calling handleSomeEvent? The most important part is missing in your code snippet. Do you have a fully working testcase implementing EntryPoint? Why do you call setText to set the value? Have you tried to disable lazyrendering?

rezdm
19 Jan 2012, 12:44 AM
Hello, Sven.

1) Where the
handleSomeEvent


is called from:




final Button myButtonAdd = new Button("Add");

myButtonAdd.addSelectionListener(new SelectionListener<ButtonEvent>()
{
@Override public void componentSelected(ButtonEvent ce)
{
final SomeSelectionDialog mySomeSelectionDialog = new SomeSelectionDialog();
mySomeSelectionDialog.addListener(Events.Hide, new Listener<BaseEvent>()
{
@Override public void handleEvent(BaseEvent be)
{
handleSomeEvent();
...








2) Unfortunately not, this is a part of a larger piece of code

3) Just tried to add to ctor theFieldTimeStart.setLazyRender(false) helped. Problem solved.

4) Just to make the picture full, here're the theFieldTimeStart with default LazyRender (note, that theFieldTimeStart.getValue() returns Time object with empty value, but getRawValue() contains proper string by the same time):
30821



Thanks!