Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
aquill
Posts: 43
Registered: ‎05-21-2010
My Device: curve 8520

return null when getDate() from DateField mode DateField.Time

Dear all,

 

can anyone explain to me why i get null value when i call getDate() method

to get value on javax.microedition.lcdui.DateField (mode DateField.Time) ?

 

here's my code to get date value :

Date dateValue = ((DateField) item).getDate();

 

fyi,

it returns null only on BB device and only on Time mode.

It works fine when i use other mode (Date, DateTime) on BB, and all mode on other device.

 

thank you,

:smileyhappy:

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: return null when getDate() from DateField mode DateField.Time

Try this

 

String date = new SimpleDateFormat(":"+"dd/MM/yyyy"+":").format(new Date(System.currentTimeMillis()));

 

---------------------------------------------------------------------------------------------------------

Press Kudoed if got Solution.

Please use plain text.
Contributor
aquill
Posts: 43
Registered: ‎05-21-2010
My Device: curve 8520

Re: return null when getDate() from DateField mode DateField.Time

dear nitiverma274,

 

 

javax.microedition.lcdui.DateField

 

 
Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: return null when getDate() from DateField mode DateField.Time

U can Also get the Time

 

String date = new SimpleDateFormat(":"+"dd/MM/yyyy"+":dd:mm:yy").format(new Date(System.currentTimeMillis()));

 

--------------------------------------------------------------------------------------------------------

Press Kudoed If Got Solution.

Please use plain text.
Contributor
aquill
Posts: 43
Registered: ‎05-21-2010
My Device: curve 8520

Re: return null when getDate() from DateField mode DateField.Time

but i want to get value from javax.microedition.lcdui.DateField mode TIME.

can u help me?

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: return null when getDate() from DateField mode DateField.Time

I would specify:

 

javax.microedition.lcdui.DateField.TIME

 

to make sure that you don't pick up the equivalent RIM DateField definition.

 

If you are doing this and still not getting anything useful, then please post the code.  I would be concerned about a bug too. 

Please use plain text.
Contributor
aquill
Posts: 43
Registered: ‎05-21-2010
My Device: curve 8520

Re: return null when getDate() from DateField mode DateField.Time

Dear peter_strange,

thank you for your reply.

 

yes, i'm using javax.microedition.lcdui.DateField on my MidletProject,

because i want to run my application on many device.

But, i have a problem when i run it on BB device.

 

Here's my simple code :

 

import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;


public class TimeMidlet extends MIDlet implements CommandListener {
	
    private Display display = Display.getDisplay(this);
    Form myForm;
    DateField myDateTime;
    DateField myDate;
    DateField myTime;
    Command okCommand = new Command("OK", Command.OK, 0);;

    public TimeMidlet() {
    }

    public void startApp() {
        
    	myForm = new Form("Test DateField");
    	
        myDateTime = new DateField("My Date Time", DateField.DATE_TIME);
        myDate = new DateField("My Date", DateField.DATE);
        myTime = new DateField("My Time", DateField.TIME);
        
        myForm.append(myDateTime);
        myForm.append(myDate);
        myForm.append(myTime);
        
        myForm.addCommand(okCommand);
        myForm.setCommandListener(this);
        
        display.setCurrent(myForm);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

	public void commandAction(Command c, Displayable d) {
		
		if (c == okCommand) {
			
			//getDate from DateField
			Date dateTimeValue = myDateTime.getDate();
			Date dateValue = myDate.getDate();
			Date timeValue = myTime.getDate();
			
			//date convert to string
			String dateTimeString = dateTimeValue.toString();
			String dateString = dateValue.toString();
			String timeString = null;
			if(timeValue!=null) {
				timeString = timeValue.toString();
			} 
			
			//display result
			myForm.append("\n\nThe Result : ");
			myForm.append("DateTime: " + dateTimeString);
			myForm.append("Date: " + dateString);
			myForm.append("Time: " + timeString);
		}
	}
}

 

 

the result of time value is null. :smileysad:

can u help me to solve this?

or is it a bug?

 

thank you,

:smileyhappy:

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: return null when getDate() from DateField mode DateField.Time

Sorry I am not a Midlet programmer and haven't time to really fully check your code.  But if you are confident that the code is not working correctly, then I suggest you put this up on Issue Tracker. 

Please use plain text.
Contributor
aquill
Posts: 43
Registered: ‎05-21-2010
My Device: curve 8520

Re: return null when getDate() from DateField mode DateField.Time

thank u,

i'll try the Issue Tracker

Please use plain text.