konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.55k stars 260 forks source link

I am having trouble binding... #904

Closed james-moliere closed 2 months ago

james-moliere commented 2 months ago

I created this code... `package org.example;

import org.teavm.jso.JSBody; import org.teavm.jso.dom.html.HTMLDocument;

//TIP To Run code, press or // click the icon in the gutter. public class Main {

@JSBody(params = { "message" }, script = "console.log(message)")
public static native void log(String message);

@JSBody(script="Icall()")
public static native void Icall();

public static void main(String[] args) {

    var document = HTMLDocument.current();
    var div = document.createElement("div");
    div.appendChild(document.createTextNode("TeaVM generated element"));
    document.getBody().appendChild(div);
    Client client = new Client();
    client.bind("application-context");

    log("done.  this is a test.");
    Icall();

}

}`

along with this code... `import org.teavm.flavour.templates.BindTemplate; import org.teavm.flavour.widgets.ApplicationTemplate;

@BindTemplate("templates/client.html") public class Client extends ApplicationTemplate {

private String userName = "";

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

} ...with an index.html ... <!DOCTYPE html>

TeaVM example

`

and a build file... `

plugins { java war id("org.teavm") version "0.9.2" }

//configurations { // create("teavmCli") // create("teavmClasslib") //}

group = "org.example" version = "1.0-SNAPSHOT"

repositories { mavenCentral() }

dependencies { implementation (teavm.libs.jsoApis) // implementation("com.frequal.flavour:teavm-flavour-templates:0.3.0") // implementation("com.frequal.flavour:teavm-flavour-json:0.3.0") // implementation("com.frequal.flavour:teavm-flavour-application:0.3.0") implementation("com.frequal.flavour:teavm-flavour-widgets:0.3.0")

}

tasks.test { useJUnitPlatform() }

java { toolchain { languageVersion = JavaLanguageVersion.of(17) } }

teavm.js { addedToWebApp = true mainClass = "org.example.Main" // debugInformation.set(true) // this is also optional, default value is .js targetFileName = "example.js" // sourceMap = true //sourceFilePolicy = SourceFilePolicy.LINK_LOCAL_FILES } `

...and get this error with the command line...

.\gradlew.bat --info clean build
Method org.teavm.jso.core.JSArray.get(I)Lorg/teavm/jso/JSObject; was not found
    at org.teavm.flavour.templates.Slot.insertBefore(Slot.java:89)
    at org.teavm.flavour.templates.Slot.append(Slot.java:29)
    at org.teavm.flavour.templates.Templates$RootComponent.<init>(Templates.java:84)
    at org.teavm.flavour.templates.Templates.bind(Templates.java:43)
    at org.teavm.flavour.widgets.ApplicationTemplate.bind(ApplicationTemplate.java:42)
    at org.teavm.flavour.widgets.ApplicationTemplate.bind(ApplicationTemplate.java:46)
    at org.example.Main.main(Main.java:39)
Method org.teavm.jso.core.JSArray.push(Lorg/teavm/jso/JSObject;)I was not found
    at org.teavm.flavour.templates.NodeHolder.getAllNodes(NodeHolder.java:40)
    at org.teavm.flavour.templates.Slot.getAllNodes(Slot.java:122)
    at org.teavm.flavour.templates.Slot.insertBefore(Slot.java:70)
    at org.teavm.flavour.templates.Slot.append(Slot.java:29)
    at org.teavm.flavour.templates.Templates$RootComponent.<init>(Templates.java:84)
    at org.teavm.flavour.templates.Templates.bind(Templates.java:43)
    at org.teavm.flavour.widgets.ApplicationTemplate.bind(ApplicationTemplate.java:42)
    at org.teavm.flavour.widgets.ApplicationTemplate.bind(ApplicationTemplate.java:46)
    at org.example.Main.main(Main.java:39)

It appears that the JSArray is in 'org.teavm.jso.core.JSArray' instead of 'org.teavm.jso.JSArray'

Any help would be appreciated.

konsoletyper commented 2 months ago

First of all, this particular repository never contained a line of code of TeaVM Flavor. What you are looking for is this one. Unfortunately, I don't maintain in for many years. I noticed that you are using Flavour fork which is base here, so I suggest that you ask its author to fix the issue. Another alternative would be to create you own fork or to send a patch to maintainer of existing fork.