ORMLite不支持GregorianCalendar映射(ORMLite does not support GregorianCalendar to be mapped)

编程入门 行业动态 更新时间:2024-10-28 10:34:30
ORMLite不支持GregorianCalendar映射(ORMLite does not support GregorianCalendar to be mapped)

我将使用ORMLite,因为我发现它非常有用......但是,我发现了一个缺点。

我有一个具有GregorianCalendar类型属性的类,其映射如下:

@DatabaseField(dataType = DataType.DATE_STRING) private GregorianCalendar fechaNacimiento;

当我运行我的应用程序时,它会在logcat中与该消息一起崩溃:

07-31 20:52:47.629:E / AndroidRuntime(11808):FATAL EXCEPTION:main 07-31 20:52:47.629:E / AndroidRuntime(11808):java.lang.RuntimeException:无法启动活动ComponentInfo {com。 joninazio.euskofest / com.joninazio.euskofest.ui.MenuPrincipalActivity}:java.lang.IllegalArgumentException:字段FieldType的字段类java.util.GregorianCalendar:name = fechaCreacion,class = Usuario对类型com.j256.ormlite无效。 field.types.DateStringType@40dca268,也许应该是班级[B 07-31 20:52:47.629:E / AndroidRuntime(11808):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)

OrmLite似乎不支持GregorianCalendar,因为它可以在这里看到: http ://ormlite.com/data_types.shtml,它表明OrmLite的DATE对应于Java的java.util.Date ...

我的问题是为什么支持一个弃用的类?

你有什么解决方案不改变GregorianCalendar吗? 也许将注释更改为

@DatabaseField(dataType = DataType.STRING)

先谢谢你。

I'm going to use ORMLite as I have found it very useful... However, I have found a disadvantage.

I have a class which has a GregorianCalendar type attribute, which is mapped as follows:

@DatabaseField(dataType = DataType.DATE_STRING) private GregorianCalendar fechaNacimiento;

When I run my app, it gets crashed with that message in logcat:

07-31 20:52:47.629: E/AndroidRuntime(11808): FATAL EXCEPTION: main 07-31 20:52:47.629: E/AndroidRuntime(11808): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.joninazio.euskofest/com.joninazio.euskofest.ui.MenuPrincipalActivity}: java.lang.IllegalArgumentException: Field class java.util.GregorianCalendar for field FieldType:name=fechaCreacion,class=Usuario is not valid for type com.j256.ormlite.field.types.DateStringType@40dca268, maybe should be class [B 07-31 20:52:47.629: E/AndroidRuntime(11808): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)

It seems that GregorianCalendar is not supported by OrmLite as it can be seen here: http://ormlite.com/data_types.shtml, which states that OrmLite's DATE corresponds to Java's java.util.Date...

And my question is why supporting a deprecated class?

Do you have any solution not to change GregorianCalendar? Perhaps changing the annotation to

@DatabaseField(dataType = DataType.STRING)

?

Thank you in advance.

最满意答案

我用一个技巧解决了这个问题:

要保留的数据更改为Date类。 更改或创建新的setter和getter。 创建GregorianCalendar属性,但该属性不持久(没有注释)。 修改Date属性的setter,指定GregorianCalendar Date的转换值。

I have solved this with a trick:

The data to be persisted change to Date class. Change or create new setters and getters. Create the GregorianCalendar attribute, but that one not persisted (without annotations). Modify the setter of the Date attribute, assign the GregorianCalendar Date's value converted.

更多推荐

本文发布于:2023-07-09 14:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1087119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   ORMLite   GregorianCalendar   mapped   support

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!