Error filling print - Casting String to Date with iReport Design

I'm studying the iReport Design report tool and, when I tried convert a String object to Date, I received the message:

Error filling print... java.util.Date cannot be cast to java.lang.String

I tried convert it using:

new SimpleDateFormat("yyyyMMdd").parse($F{date})

$F{date} is the String that I get from the query. I try convert it in the Pattern Expr. of Text Field Properties of the $F{date}.

This don't work with Expression Class java.land.String and don't work with java.util.Date.

jorgew.moura's picture
Joined: Feb 14 2018 - 11:33am
Last seen: 11 months 5 hours ago

1 Answer:

In a similar situation I had to make scriptlet with this

public String toDateFormat (String dateInput, String desiredFormat, String existingFormat ){
    SimpleDateFormat sdfOld = new SimpleDateFormat(existingFormat);
    Date date = null;
    try {
        date = sdfOld.parse(dateInput);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    SimpleDateFormat sdfNew = new SimpleDateFormat(desiredFormat);
    return String.valueOf(sdfNew.format(date));
}

to be able affectively manage it. Surely it's reloaded with default formats that I use, to make it simplier, but approach still the same.

sergey.vishnevetskiy's picture
Joined: Jan 2 2018 - 10:13am
Last seen: 3 years 4 months ago
Feedback
randomness