Problem running Javafx hello world application

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem running Javafx hello world application

Tony West
Hi,

Based on what I've seen in the mailing list, I've got the following simple Javafx application:

(module-name <org.kawa.javafx>)
(module-extends <javafx.application.Application>)
(module-export start create-button)
(module-compile-options main: #t)

;;
;;; Application
;;

(define (start (primary-stage :: <javafx.stage.Stage>)) :: <void>
  (invoke primary-stage 'setTitle "Hello World!")
  (let ((root-pane (<javafx.scene.layout.StackPane>))
        (button (create-button
                 text: "Say 'Hello World'"
                 event-handler: (lambda (event) (format #t "Hello World!")))))
    (invoke (invoke root-pane 'getChildren) 'add button)
    (invoke primary-stage 'setScene (<javafx.scene.Scene> root-pane 300 250))
    (invoke primary-stage 'show)))

;;
;;; Utilities
;;

(define (create-button #!key (text #f) (event-handler #f)) :: <javafx.scene.control.Button>
  (let ((button :: <javafx.scene.control.Button> (<javafx.scene.control.Button>)))
    (when text
      (invoke button 'setText text))

    (when event-handler
      (invoke button 'setOnAction (object (<javafx.event.EventHandler>)
                                    ((handle (event :: <javafx.event.ActionEvent>))
                                      (event-handler event)))))

    button))


;;
;;; Main
;;

(define (main)
  (invoke-static <org.kawa.javafx> 'launch))

(main)

When compiling I get the following:

E:\Work\kawa>kawa --main -C hello-world.scm
Jun 07, 2017 4:16:42 PM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
(compiling hello-world.scm to org.kawa.javafx)

And when I run it I get the following:

E:\Work\kawa>java org.kawa.javafx
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.IncompatibleClassChangeError: Expected static field org.kawa.javafx$frame.$main
        at org.kawa.javafx.main(hello-world.scm)
        ... 11 more
Exception running application org.kawa.javafx

I would be really grateful if someone could point out what I am doing wrong.

Thanks.

Tony

Reply | Threaded
Open this post in threaded view
|

Re: Problem running Javafx hello world application

Damien Mattei
just for test, if you try this:
(define (main)
(let ((tst (invoke-static <org.kawa.javafx> 'launch)))
'())
)
does it change something?

i  think the probleme comes that you try to return a static object at the level (toplevel or REPL) of a java function,
if the main function is dynamically generated it can not return a static field, for incomatibility reason, i had such incompatibility problem in a pure java program.

Damien

Le Wednesday 07 June 2017 08:27:17 Tony West, vous avez écrit :

> Hi,
>
> Based on what I've seen in the mailing list, I've got the following simple Javafx application:
>
> (module-name <org.kawa.javafx>)
> (module-extends <javafx.application.Application>)
> (module-export start create-button)
> (module-compile-options main: #t)
>
> ;;
> ;;; Application
> ;;
>
> (define (start (primary-stage :: <javafx.stage.Stage>)) :: <void>
>   (invoke primary-stage 'setTitle "Hello World!")
>   (let ((root-pane (<javafx.scene.layout.StackPane>))
>         (button (create-button
>                  text: "Say 'Hello World'"
>                  event-handler: (lambda (event) (format #t "Hello World!")))))
>     (invoke (invoke root-pane 'getChildren) 'add button)
>     (invoke primary-stage 'setScene (<javafx.scene.Scene> root-pane 300 250))
>     (invoke primary-stage 'show)))
>
> ;;
> ;;; Utilities
> ;;
>
> (define (create-button #!key (text #f) (event-handler #f)) :: <javafx.scene.control.Button>
>   (let ((button :: <javafx.scene.control.Button> (<javafx.scene.control.Button>)))
>     (when text
>       (invoke button 'setText text))
>
>     (when event-handler
>       (invoke button 'setOnAction (object (<javafx.event.EventHandler>)
>                                     ((handle (event :: <javafx.event.ActionEvent>))
>                                       (event-handler event)))))
>
>     button))
>
>
> ;;
> ;;; Main
> ;;
>
> (define (main)
>   (invoke-static <org.kawa.javafx> 'launch))
>
> (main)
>
> When compiling I get the following:
>
> E:\Work\kawa>kawa --main -C hello-world.scm
> Jun 07, 2017 4:16:42 PM org.jline.utils.Log logr
> WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
> (compiling hello-world.scm to org.kawa.javafx)
>
> And when I run it I get the following:
>
> E:\Work\kawa>java org.kawa.javafx
> java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         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(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
> Caused by: java.lang.IncompatibleClassChangeError: Expected static field org.kawa.javafx$frame.$main
>         at org.kawa.javafx.main(hello-world.scm)
>         ... 11 more
> Exception running application org.kawa.javafx
>
> I would be really grateful if someone could point out what I am doing wrong.
>
> Thanks.
>
> Tony
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Problem running Javafx hello world application

Tony West
Hi Damien,

I tried the change.

During compilation I received the following messages:

E:\Work\kawa>kawa --main -C hello-world.scm
Jun 08, 2017 6:46:08 AM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
(compiling hello-world.scm to org.kawa.javafx)
hello-world.scm:41:12: warning - void-valued expression where value is needed

When I attempted to run it, the same error messages as before appeared.

Tony
________________________________________
From: [hidden email] <[hidden email]> on behalf of Damien MATTEI <[hidden email]>
Sent: Wednesday, 7 June 2017 7:13 PM
To: [hidden email]
Subject: Re: Problem running Javafx hello world application

just for test, if you try this:
(define (main)
(let ((tst (invoke-static <org.kawa.javafx> 'launch)))
'())
)
does it change something?

i  think the probleme comes that you try to return a static object at the level (toplevel or REPL) of a java function,
if the main function is dynamically generated it can not return a static field, for incomatibility reason, i had such incompatibility problem in a pure java program.

Damien

Le Wednesday 07 June 2017 08:27:17 Tony West, vous avez écrit :

> Hi,
>
> Based on what I've seen in the mailing list, I've got the following simple Javafx application:
>
> (module-name <org.kawa.javafx>)
> (module-extends <javafx.application.Application>)
> (module-export start create-button)
> (module-compile-options main: #t)
>
> ;;
> ;;; Application
> ;;
>
> (define (start (primary-stage :: <javafx.stage.Stage>)) :: <void>
>   (invoke primary-stage 'setTitle "Hello World!")
>   (let ((root-pane (<javafx.scene.layout.StackPane>))
>         (button (create-button
>                  text: "Say 'Hello World'"
>                  event-handler: (lambda (event) (format #t "Hello World!")))))
>     (invoke (invoke root-pane 'getChildren) 'add button)
>     (invoke primary-stage 'setScene (<javafx.scene.Scene> root-pane 300 250))
>     (invoke primary-stage 'show)))
>
> ;;
> ;;; Utilities
> ;;
>
> (define (create-button #!key (text #f) (event-handler #f)) :: <javafx.scene.control.Button>
>   (let ((button :: <javafx.scene.control.Button> (<javafx.scene.control.Button>)))
>     (when text
>       (invoke button 'setText text))
>
>     (when event-handler
>       (invoke button 'setOnAction (object (<javafx.event.EventHandler>)
>                                     ((handle (event :: <javafx.event.ActionEvent>))
>                                       (event-handler event)))))
>
>     button))
>
>
> ;;
> ;;; Main
> ;;
>
> (define (main)
>   (invoke-static <org.kawa.javafx> 'launch))
>
> (main)
>
> When compiling I get the following:
>
> E:\Work\kawa>kawa --main -C hello-world.scm
> Jun 07, 2017 4:16:42 PM org.jline.utils.Log logr
> WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
> (compiling hello-world.scm to org.kawa.javafx)
>
> And when I run it I get the following:
>
> E:\Work\kawa>java org.kawa.javafx
> java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         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(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
> Caused by: java.lang.IncompatibleClassChangeError: Expected static field org.kawa.javafx$frame.$main
>         at org.kawa.javafx.main(hello-world.scm)
>         ... 11 more
> Exception running application org.kawa.javafx
>
> I would be really grateful if someone could point out what I am doing wrong.
>
> Thanks.
>
> Tony
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Problem running Javafx hello world application

Per Bothner
In reply to this post by Tony West
On 06/06/2017 11:27 PM, Tony West wrote:

> I would be really grateful if someone could point out what I am doing wrong.

Hm.  It works for me.  Though I suggest changing the event handler to:

                  event-handler: (lambda (event) (format #t "Hello World!~%~!")))))

What OS and version of Kawa are you using?

I'm using Kawa 2.93-23-g4fa24f2-dirty (using kawa --version), on Fedora 25.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Problem running Javafx hello world application

Per Bothner
On 06/07/2017 11:56 PM, Tony West wrote:
> Hi,
>
> I made the change to the event handler but it still fails with the same error.
>
> I am running the following:
>
> C:\Users\Tony>kawa --version
> Kawa 2.4 (git describe: kawa-2.3-30-gdad3755-dirty)
> Copyright (C) 2017 Per Bothner

That's rather old.  The version number I get is 2.93-23-g4fa24f2-dirty
- i.e. the current version of the master branch.  I do get the same bug
as you when I try the 2.4 branch.

I will sometimes check fixes into the 2.4 branch if it makes sense and
it is easy to do so, but I can't afford to spend the time debugging and
fixing problems in old versions.  (That is what a support contract would
be for.)  This doesn't look like a trivial problem, so I'm just going
to suggest you upgrade to the development version of Kawa.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Problem running Javafx hello world application

Tony West
Hi Per,

OK, I will try with the latest version of Kawa.

Thanks for your help with this.

Tony
________________________________________
From: [hidden email] <[hidden email]> on behalf of Per Bothner <[hidden email]>
Sent: Friday, 9 June 2017 12:13 AM
To: Tony West
Cc: Kawa mailing list
Subject: Re: Problem running Javafx hello world application

On 06/07/2017 11:56 PM, Tony West wrote:
> Hi,
>
> I made the change to the event handler but it still fails with the same error.
>
> I am running the following:
>
> C:\Users\Tony>kawa --version
> Kawa 2.4 (git describe: kawa-2.3-30-gdad3755-dirty)
> Copyright (C) 2017 Per Bothner

That's rather old.  The version number I get is 2.93-23-g4fa24f2-dirty
- i.e. the current version of the master branch.  I do get the same bug
as you when I try the 2.4 branch.

I will sometimes check fixes into the 2.4 branch if it makes sense and
it is easy to do so, but I can't afford to spend the time debugging and
fixing problems in old versions.  (That is what a support contract would
be for.)  This doesn't look like a trivial problem, so I'm just going
to suggest you upgrade to the development version of Kawa.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/