Thanks @Jens

So I added *namespace = JsPackage.GLOBAL* as suggested:

package com.project.client;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class Car {
 @JsProperty(namespace = JsPackage.GLOBAL) public static Car car;

  public native String start();
}

But the new stacktrace is:

SEVERE: 
java.lang.ClassCastException
  at Unknown.xk_g$(Throwable.java:69)
  at Unknown.el_g$(Exception.java:29)
  at Unknown.ml_g$(RuntimeException.java:29)
  at Unknown.BXe_g$(ClassCastException.java:27)
  at Unknown.dyg_g$(InternalPreconditions.java:154)
  at Unknown.pyg_g$(InternalPreconditions.java:138)
  at Unknown.oyg_g$(InternalPreconditions.java:133)
  at Unknown.c9c_g$(Cast.java:155)
  at Unknown.ose_g$(App.java:74)
  at Unknown.Fse_g$(App.java:66)
  at Unknown.rfb_g$(SchedulerImpl.java:50)
  at Unknown.Xeb_g$(SchedulerImpl.java:183)
  at Unknown.Seb_g$(SchedulerImpl.java:347)
  at Unknown.jfb_g$(SchedulerImpl.java:78)
  at Unknown.Peb_g$(SchedulerImpl.java:141)
  at Unknown.ydb_g$(Impl.java:309)
  at Unknown.Bdb_g$(Impl.java:361)
  at Unknown.anonymous(Impl.java:78)

Other ideas?


On Tuesday, May 12, 2020 at 7:14:33 PM UTC+10, Jens wrote:
>
> I am not 100% sure since I have not used JsInterop for a long time now but 
> I would imagine the following:
>
> Currently GWT will think that your native JS class "Car" is located at 
> com.project.client namespace because that is the package it lives in and 
> you have not provided a namespace to @JsType.
>
> You can access the static car field because you have added the global 
> namespace to @JsProperty and your custom JS has created a car field in that 
> global namespace. In your for-loop I am relatively sure that GWT will try 
> to verify that your Java list contains actual JS Cars so the generated JS 
> will somewhere contain "$wnd.com.project.client.Car" which is undefined 
> since your JS did not define it (you have defined everything in the global 
> space, including the class itself)
>
> So you should use @JsType(isNative = true, namespace = JsPackage.GLOBAL) 
> on your Car class to tell GWT to use $wnd.Car since that is the location 
> where you have defined that class in JS.
>
>
> -- J.
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/44bdc332-2540-4393-a650-741877a9ee55%40googlegroups.com.

Reply via email to