为什么 com.google.gwt.i18n.shared.DateTimeFormat 调用 Gwt.create
Why does com.google.gwt.i18n.shared.DateTimeFormat call Gwt.create
在我的共享代码中,我将 com.google.gwt.i18n.client.DateTimeFormat
替换为 com.google.gwt.i18n.shared.DateTimeFormat
,以避免 here 提议的 Gwt.create
出现运行时问题。
我现在的问题是,DateTimeFormat.getFormat
调用 getDefaultDateTimeFormatInfo
而调用 LocaleInfo.getCurrentLocale().getDateTimeFormatInfo()
。 LocaleInfo
是通过 new LocaleInfo((LocaleInfoImpl)GWT.create(LocaleInfoImpl.class), (CldrImpl)GWT.create(CldrImpl.class))
.
实例化的单例
在我的测试中,结果是 ExceptionInInitializerError
。
java.lang.ExceptionInInitializerError
at com.google.gwt.i18n.shared.DateTimeFormat.getDefaultDateTimeFormatInfo(DateTimeFormat.java:681)
at com.google.gwt.i18n.shared.DateTimeFormat.getFormat(DateTimeFormat.java:665)
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.shared.GWT.create(GWT.java:66)
at com.google.gwt.core.client.GWT.create(GWT.java:86)
at com.google.gwt.i18n.client.LocaleInfo.<clinit>(LocaleInfo.java:36)
... 27 more
所以我真的很惊讶共享 class 调用 Gwt.create
。根据我对 GWT 工作原理的理解,情况不应如此。如果我错了,请纠正我。
至少我认为,这是一个已知问题:https://github.com/gwtproject/gwt/issues/7668
相反,您可以提供:
https://github.com/vegegoku/gwt-i18n-apt
一试。
但不确定是否已经完全迁移。你可以在这里问:https://gitter.im/gwtproject/gwt-modules
在我的共享代码中,我将 com.google.gwt.i18n.client.DateTimeFormat
替换为 com.google.gwt.i18n.shared.DateTimeFormat
,以避免 here 提议的 Gwt.create
出现运行时问题。
我现在的问题是,DateTimeFormat.getFormat
调用 getDefaultDateTimeFormatInfo
而调用 LocaleInfo.getCurrentLocale().getDateTimeFormatInfo()
。 LocaleInfo
是通过 new LocaleInfo((LocaleInfoImpl)GWT.create(LocaleInfoImpl.class), (CldrImpl)GWT.create(CldrImpl.class))
.
在我的测试中,结果是 ExceptionInInitializerError
。
java.lang.ExceptionInInitializerError
at com.google.gwt.i18n.shared.DateTimeFormat.getDefaultDateTimeFormatInfo(DateTimeFormat.java:681)
at com.google.gwt.i18n.shared.DateTimeFormat.getFormat(DateTimeFormat.java:665)
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.shared.GWT.create(GWT.java:66)
at com.google.gwt.core.client.GWT.create(GWT.java:86)
at com.google.gwt.i18n.client.LocaleInfo.<clinit>(LocaleInfo.java:36)
... 27 more
所以我真的很惊讶共享 class 调用 Gwt.create
。根据我对 GWT 工作原理的理解,情况不应如此。如果我错了,请纠正我。
至少我认为,这是一个已知问题:https://github.com/gwtproject/gwt/issues/7668
相反,您可以提供:
https://github.com/vegegoku/gwt-i18n-apt
一试。
但不确定是否已经完全迁移。你可以在这里问:https://gitter.im/gwtproject/gwt-modules