GWT导出器从GWT.create强制转换为异常;试图在GWT-Exporter中使用mvp4g,但GWT.create无法正常工作 [英] GWT exporter cast exception from GWT.create; Tried to use mvp4g with GWT-Exporter but GWT.create didn't work

查看:80
本文介绍了GWT导出器从GWT.create强制转换为异常;试图在GWT-Exporter中使用mvp4g,但GWT.create无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用GWT-Exporter,当我复制示例时,它工作得很好.然后我尝试导出一个mvp4g Presenter 这是我所做的:

I tried to use GWT-Exporter and it worked just fine when I copied the example. Then I tried to export an mvp4g Presenter Here's what I did:

@Export()
@Presenter(view = RegisterPluginDisplay.class)
public class RegisterPluginPresenterImpl extends BasePresenter<RegisterPluginView, MyBus implements RootPresenter { ... }

public interface RegisterPluginPresenter extends Exportable { ... }

//then in the start event I said:
ExporterUtil.exportAll();

它给了我这个错误:

Uncaught java.lang.AssertionErrorcom_mvp4g_client_Mvp4gModuleImpl_com_mvp4g_client_Mvp4gModuleGinjector_com_mvp4g_client_Mvp4gModule…:62 get_Key$type$com$joseph$draw4$client$presenter$RegisterPluginPresenterImpl$_annotation$$none$$_0_g$com_mvp4g_client_Mvp4gModuleImpl_com_mvp4g_client_Mvp4gModuleGinjectorImpl.java:34 getcom_joseph_draw4_client_presenter_RegisterPluginPresenterImpl_0_g$Mvp4gModuleImpl.java:101 createAndStartModule_0_g$Mvp4gEntryPoint.java:35 onModuleLoad_5_g$com_00046joseph_00046draw4_00046Draw4JUnit__EntryMethodHolder.java:3 init_2_g$ModuleUtils.java:44 initializeModules_0_g$Impl.java:247 apply_0_g$Impl.java:306 entry0_0_g$Impl.java:72 (anonymous function)ModuleUtils.java:55 gwtOnLoad_0_g$Map.java:29 (anonymous function)

我查看了一下代码,发现GWT.create()在创建演示者时没有成功.我尝试创建一个导出的类,然后在其上使用GWT.create,发现即使我不执行ExporterUtils.exportAll(),也无法将GWT.create与实现Exportable的任何类一起使用. Exportable接口的文档说GWT.create()语句返回Exportable.这就解释了类强制转换异常.那我该如何解决呢?

I looked at the code and found that GWT.create() was unsucessful in creating the presenter. I tried to create an exported class and then using GWT.create on it and found that I can't use GWT.create with any class that implements Exportable even if I don't do ExporterUtils.exportAll(). The documentation for the Exportable interface says that the GWT.create() statement returns an Exportable. That explains the class cast exception. So how do I fix this?

推荐答案

我转而使用实验性js互操作,但仍然遇到相同的问题. Mvp4g使用gin来获取Presenter.根据杜松子酒Wiki 为了实例化它,如果GIN找不到类的绑定,则它会回退到对该类调用GWT.create()".它不能在Exportable上使用GWT.create,因为GWT.create(一个Exportable)返回一个Exporter.就像文档中所说的那样,您必须绑定该类才能不使用GWT.create.解决方案是为该类添加一个绑定.我只需要进入GinModule的configure方法并添加以下代码行即可:

I switched to using the experimental js interop and still got the same problem. Mvp4g uses gin to get the Presenter. According to the gin wiki "if GIN can't find a binding for a class, it falls back to calling GWT.create() on that class" in order to instantiate it. It can't use GWT.create on an Exportable because GWT.create(an Exportable) returns an Exporter. Like the documentation says you have to bind the class for it to not use GWT.create. The solution is to add a binding for the class. I just had to go in the configure method of my GinModule and add this line of code:

bind(MyPresenter.class).toProvider(MyPresenterProvider.class);

然后我必须创建MyPresenterProvider类:

Then I had to create the MyPresenterProvider class:

public static class MyPresenterProvider.class implements Provider<MyPresenter> {
      @Override
    public MyPresenter get() {
        return new MyPresenter();
    }

这篇关于GWT导出器从GWT.create强制转换为异常;试图在GWT-Exporter中使用mvp4g,但GWT.create无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆