Groovy с JavaFX GroovyObject не найден в экстракторе для ObservableList - PullRequest
0 голосов
/ 29 мая 2018

Я пытаюсь создать ObservableList некоторого типа User, который будет уведомлять любой listchangelistener, если один из элементов, хранящихся в нем, изменил какое-либо из его значений.

Хотя обратный вызов всегда вызывает исключение:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
    at org.codehaus.groovy.runtime.ProxyGeneratorAdapter$InnerLoader.defineClass(ProxyGeneratorAdapter.java:926)
    at org.codehaus.groovy.runtime.ProxyGeneratorAdapter.<init>(ProxyGeneratorAdapter.java:191)
    at groovy.util.ProxyGenerator.createAdapter(ProxyGenerator.java:233)
    at groovy.util.ProxyGenerator.instantiateDelegateWithBaseClass(ProxyGenerator.java:208)
    at groovy.util.ProxyGenerator.instantiateDelegateWithBaseClass(ProxyGenerator.java:192)
    at groovy.util.ProxyGenerator.instantiateDelegate(ProxyGenerator.java:184)
    at groovy.util.ProxyGenerator.instantiateDelegate(ProxyGenerator.java:180)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:15768)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:10859)
    at org.codehaus.groovy.runtime.dgm$53.doMethodInvoke(Unknown Source)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
    at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:935)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:926)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:181)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asType(ScriptBytecodeAdapter.java:604)
    at sample.Main$1.call(Main.groovy:36)
    at sample.Main$1.call(Main.groovy)
    at com.sun.javafx.collections.ElementObserver.attachListener(ElementObserver.java:79)
    at com.sun.javafx.collections.ObservableListWrapper.doAdd(ObservableListWrapper.java:100)
    at javafx.collections.ModifiableObservableListBase.add(ModifiableObservableListBase.java:151)
    at java.util.AbstractList.add(AbstractList.java:108)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
    at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:99)
    at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:192)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
    at sample.Main.start(Main.groovy:39)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:702)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:812)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:800)
    ... 47 more
Exception running application sample.Main

Я смог воспроизвести ошибку в следующем примере:

package sample

import javafx.application.Application
import javafx.beans.Observable
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.Scene
import javafx.scene.control.ComboBox
import javafx.stage.Screen
import javafx.stage.Stage
import javafx.util.Callback

class Main extends Application {

    static void main(String[] args) {
        launch(Main.class, args)

    }

    class User {
        String name
        User(String t){
            name = t
        }
    }

    @Override
    void start(Stage primaryStage) {

        ObservableList<User> usersTest =
                FXCollections.observableArrayList(new Callback<User, Observable[]>() {
                    @Override
                    Observable[] call(User o) {
                        return [o] as Observable
                    }
                })
        usersTest.addAll( new User("John"), new User("Jane"))

        ComboBox<User> cb = new ComboBox<>()
        cb.setItems(usersTest)

        cb.value = cb.items.first()

        def bounds = Screen.primary.bounds
        Scene scene = new Scene(cb, bounds.width, bounds.height)
        primaryStage.setScene(scene)
        primaryStage.show()
    }
}

Честно говоря, у меня немного не хватает опций, поскольку ошибка настолько бесполезна, насколько это возможно.

...