Friday, 15 May 2015

IllegalAccessException while using java object in javascript -



IllegalAccessException while using java object in javascript -

i'm going utilize webview/webengine display "logs" (i.e. chat message, game status message, ...) simple multiplayer game.

here wrote on javascript part.

class="lang-js prettyprint-override">function addlogmessage(o) { var kind = o.getmessagekindcase(); if (kind.equals(kind.chat_message)) { $("body").append(createchatmessage(o.getchatmessage())); } else (/* other cases following... */) } function addlogmessages(l) { var n = l.size(); (var = 0; < n; i++) { addlogmessage(l.get(i)); } }

here wrote on java part.

class="lang-java prettyprint-override">private gamestatus gamestatus; private webengine logwebengine; private final objectproperty<jsobject> window = new simpleobjectproperty<>(this, "window"); public void initialize(url url, resourcebundle rb) { gamestatus = /* ... */; window.addlistener((o, oldvalue, newvalue) -> { if (newvalue == null) { return; } // getlogmessages() homecoming java.util.list<logmessage> newvalue.call("addlogmessages", gamestatus.getlogmessages()); }); logwebengine = logview.getengine(); logwebengine.getloadworker().stateproperty().addlistener((o, oldvalue, newvalue) -> { if (newvalue == worker.state.succeeded) { window.set((jsobject) logwebengine.executescript("window")); } }); logwebengine.load(getclass().getresource("log.html").tostring()); }

when called addlogmessage() java side, works intended. however, calling addlogmessages() caused next exception.

exception in thread "javafx application thread" java.lang.illegalaccessexception: class sun.reflect.misc.trampoline can not access fellow member of class java.util.collections$unmodifiablecollection modifiers "public"

it seems l.size() in addlogmessages caused exception.

what's reason of exception? and, there solution issue? in advance.

the comment of zella helpful me.

did not work:

datumfunction<double> datumfunction = new datumfunction<double>(){ @override public double apply(int d) { string result = "" + d; homecoming value; } };

does work:

datumfunction<double> datumfunction = new doubledatumfunction();

with

public class doubledatumfunction implements datumfunction<double> { @override public string apply(int d) { string result = "" + d; homecoming value; } }

if remove public modifier class sec example, illustration not work more.

java javascript javafx javafx-webengine

No comments:

Post a Comment