Hi there,

I'm using Sun's KJava VM and I am experiencing some trouble when I call the
Runtime.date() method. What I'm trying to do is to just assign an instance
variable of type String the string representing the current date.

What I first tried to do was something like this:

    String date_s;

    private void getDate() {
        byte[] date = Runtime.date();
        StringBuffer text = new StringBuffer();
        for(int i = 0; i < date.length && date[i] != 0; i++)
            text.append((char) date[i]);
        date_s = text.toString();
    }

This does not work at all! Either, I get a null pointer exception at the
line
        for(int i = ....
or I get some kind of "Fatal error" and my handheld resets.
I have experience much weirdness during debugging! For example, if I try to
check if date is null with something like

    if(date == null)
        g.drawString("date is null!", 0, 0);

I can't even compile!!!
The only thing I have got to work is this ugly utterly stupid code snippet,
copied from a sample:

    static byte[] noteRecord = new byte[9];

    private void makeNote() {
        byte[] date = Runtime.date();
        int i;
        for(i = 0; i < 9 && date[i] != 0; i++)
            noteRecord[i] = date[i];
        noteRecord[i] = 0;
    }

    private String displayNoteText() {
        StringBuffer text = new StringBuffer();
        for(int i = 0; i < 9 && (char) noteRecord[i] != (char) 0; i++)
            text.append((char) noteRecord[i]);
        return text.toString();
    }

    private void getDate() {
        makeNote();
        date_s = displayNoteText();
    }

Does anyone have any idea 'bout what's going on?

TIA

Malin



Reply via email to