BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-25-2006, 03:30 PM   #1
noura20
New Member
 
Join Date: Jan 2006
Model: 7290
Posts: 6
Default DateField Problem

Please Login to Remove!

Hello, I am having a problem with the DateField that comes with the RIM API.

I am writing an application that allows a user to select a date and time, and enter prices etc. I cannot access the contents of the DateField in another class, yet I can access the contents of my other fields (textfields, checkbox fields).

I declare a DateField object as follows (inside a class that extends MainScreen):

mgr.add(new LabelField("Effective Date: "));
DateField dateField = new DateField("", System.currentTimeMillis(), DateField.DATE | DateField.USE_ALL_WIDTH);
mgr.add(dateField);

Has anyone dealt with DateField?? Any suggestions would be great.

Noura
Offline  
Old 01-25-2006, 04:40 PM   #2
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

How are you trying to access the DateField object (getDate())?

Make sure you are using the net.rim.device.api.ui.component.DateField and not the midp ui DateField.
Offline  
Old 01-26-2006, 07:55 AM   #3
noura20
New Member
 
Join Date: Jan 2006
Model: 7290
Posts: 6
Default

Hi eradis,

Yes, I am trying to access the DateField object's getDate() method.

I am importing "net.rim.device.api.ui.*;" so I assume that the midp DateField is not being used. (Is there another way to check to make sure?)

Basically, I set up the screen in one method, and then in another, I retrieve the data with for example:

price.getPrice();
faxflag.getFaxflag();

These methods are my own, and they work fine. However, when I type:

"dateField."

the JDE offers me a list of methods to select from but not the getDate().
Offline  
Old 01-26-2006, 08:10 AM   #4
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

First make sure you are not importing javax.microedition.lcdui.* (The javax....DateField is being imported - but it provides a getDate() method as well).

Did you try manually typing dateField.getDate() and compiling? It may be something with the JDE auto complete?
Offline  
Old 01-26-2006, 08:52 AM   #5
noura20
New Member
 
Join Date: Jan 2006
Model: 7290
Posts: 6
Default

Thanks for your reply eradis,
I checked in my files and in my libs, and javax.microedition.lcdui is not imported.

I added the following lines of code:

long testdate = dateField.getDate();
System.out.println("a date:" + testdate);

When I debug, I get a java.lang.NullPointerException and I checked to make sure that nothing else is causing this exception.

I am working on a workaround for this with a fieldchangelistener for the datefield. the problem with that is that it yields a field string as a parameter. I can't just do some checking of the sort: compare it to current time, if smaller, fire an alert etc
Offline  
Old 02-09-2006, 04:58 PM   #6
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

noura20,

I have yet to figure out the best way to deal with DateFields on the BB. It doesn't seem that you were meant to do things the easy like you suggest dateField.getDate().

What I have done that works (but is ugly) is to create a Calendar variable for the date I want to display in the DateField. When I want to deal with what the user has entered in the field, I have to take the data from the field as a String and set the individual fields of the Calendar variable.

You can then use the Calendar variable to do your before/after comparisons or further manipluation.

I welcome suggestions if there is an easier way...

Here's a chunk of code to try and show you what I mean:

Code:
package com.yourname.datetest;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.util.*;
import java.util.*;

public final class TestScreen extends MainScreen {

    // Screen fields
    private DateField test;
    
    private SimpleDateFormat myDtTm = new SimpleDateFormat("MM/dd/yy HH:mm");
    private Calendar testDt = Calendar.getInstance();
    
    public TestScreen() {
        // I didn't need resolution of sec or msec, so I zero them
        testDt.set(Calendar.SECOND, 0);
        testDt.set(Calendar.MILLISECOND, 0);

        test = new DateField("Date/Time: ", testDt.getTime().getTime(), myDtTm, Field.FIELD_LEFT);
        add(arv);
    }
            
    protected void makeMenu( Menu menu, int instance ) {
        MenuItem save = new MenuItem("Save", 40, 40) {
            public void run() {
                Calendar newTest = Calendar.getInstance();
                Calendar testDt = Calendar.getInstance();
                Date date = new Date();
                boolean isError = false;
                
                // Validate data
                String newDtTm = test.toString();
                // Calendar variable stores months relative to 0, ie Jan = 0, ...
                newTest.set(Calendar.MONTH, Integer.parseInt(newArvDtTm.substring(0, 2))-1);
                newTest.set(Calendar.DATE, Integer.parseInt(newArvDtTm.substring(3,5)));
                // Calendar variable needs the entire year, ie, 06 is not 2006
                newTest.set(Calendar.YEAR, 2000+Integer.parseInt(newArvDtTm.substring(6,8)));
                newTest.set(Calendar.HOUR_OF_DAY, Integer.parseInt(newArvDtTm.substring(9,11)));
                newTest.set(Calendar.MINUTE, Integer.parseInt(newArvDtTm.substring(12)));
                newTest.set(Calendar.SECOND, 0);
                newTest.set(Calendar.MILLISECOND, 0);
                    
                // If Date/Time more than 1 hour in future, error, retry 
                // *don't forget working in msec*
                date.setTime(testDt.getTime().getTime()+60L*60L*1000L);
                testDt.setTime(date);
                if (newTest.after(testDt)) {
                    isError = true;
                    Dialog.inform("Date/Time cannot be more than one hour greater than current time");
                }

                // If no errors                    
                if (!isError) {
                    // Do whatever you want with the data here ...
                    // Close this screen, on to next?
                    UiApplication.getUiApplication().popScreen(TestScreen.this);
                }
            }
        };
                
            
        MenuItem quit = new MenuItem("Quit", 40, 40) {
            public void run() {
                if (Dialog.ask(Dialog.D_YES_NO, "Are you sure you want to quit and lose all information?", Dialog.NO) == Dialog.YES) {
                    UiApplication.getUiApplication().popScreen(TestScreen.this);
                }
            }
        };
        
        menu.add(save);    
        menu.add(quit);
    }
    
    public boolean onClose() {
        if (Dialog.ask(Dialog.D_YES_NO, "Are you sure you want to quit and lose all information?", Dialog.NO) == Dialog.YES) {
            UiApplication.getUiApplication().popScreen(TestScreen.this);
            return true;
        } else {
            return false;
        }
    }
    
}
Offline  
Old 02-10-2006, 12:25 PM   #7
noura20
New Member
 
Join Date: Jan 2006
Model: 7290
Posts: 6
Default

Hi fbrimm,

Thanks for your suggestion. I actually got it to work by initializing a long variable outside my screen, and then using a focuschange listener to update that variable. I also instantiated a DateFormat object to format the date in a different way.

glad that works

Noura
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


US Stock 10 Units 100K B100K OHM Linear Taper Rotary Potentiometer POT Red Knob picture

US Stock 10 Units 100K B100K OHM Linear Taper Rotary Potentiometer POT Red Knob

$9.49



10-Turn Rotary Potentiometer Variable Dial Resistor Precision Multiturn Blue 1/4 picture

10-Turn Rotary Potentiometer Variable Dial Resistor Precision Multiturn Blue 1/4

$7.75



US Stock 10pcs 50K ohm Linear Taper Rotary Potentiometer Panel pot B50K 20mm picture

US Stock 10pcs 50K ohm Linear Taper Rotary Potentiometer Panel pot B50K 20mm

$12.21



10 turn Potentiometer 3590S Wirewound Variable Resistor Precision multi-turn POT picture

10 turn Potentiometer 3590S Wirewound Variable Resistor Precision multi-turn POT

$51.49



US Stock 10pcs 100K ohm Linear Taper Rotary Potentiometer Panel pot B100K 15mm picture

US Stock 10pcs 100K ohm Linear Taper Rotary Potentiometer Panel pot B100K 15mm

$12.05



US Stock 10 Units 10K B10K OHM Linear Taper Rotary Potentiometer POT Blue Knob picture

US Stock 10 Units 10K B10K OHM Linear Taper Rotary Potentiometer POT Blue Knob

$9.39







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.