Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#<NoMethodError: undefined method `layout_scene' for #<Java::JavafxStage::Stage:0x5eea82fc>> #24

Closed
edubkendo opened this issue Feb 7, 2013 · 5 comments

Comments

@edubkendo
Copy link
Member

So, I've been doing some experiments the past few days trying to figure out the webstart stuff, and in doing so hit upon a weird bug. If I have a jruby-complete.jar with jrubyfx copied in, I can certainly run jrubyfx apps with it like:
java -jar jruby-complete.jar hello.rb and it works like a charm. But given the same jar, let's say I have this ruby class:

require "jrubyfx"

class Hello < JRubyFX::Application

  def start(stage)
    with(stage, title: "Hello JRuby", x: 105, y: 140) do
      stage.layout_scene(500, 250, :black)  do
        hbox(padding: insets(60)) do
          text('JRuby', font: font('sanserif', 80)) do
            fill linear_gradient(0,0,0,1, true, :no_cycle, [stop(0, :pale_green), stop(1, :sea_green)])
          end
          text('FX', font: font('sanserif', 80)) do
            fill linear_gradient(0,0,0,1, true, :no_cycle, [stop(0, :cyan), stop(1, :dodger_blue)])
            set_effect(drop_shadow(color: :dodger_blue, radius: 25,spread: 0.25))
          end
        end
      end
      show
    end
  end
end
Hello.launch

And try to call it from a launcher like this:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.concurrent.Task;
import org.jruby.embed.ScriptingContainer;

public class Launcher extends Application {
  public static void main(final String[] args) {
    Application.launch(args);
  }

    public void start(final Stage stage) throws Exception
    {

       Task task = new Task<Void>()
       {
           @Override
           protected Void call() throws Exception
           {
               ScriptingContainer container = new ScriptingContainer();
               container.runScriptlet("require 'hello.rb'");
               return null;
           }
       };

       new Thread(task).start();
    }
}

Then I get the following error:

Exception running Application:
#<NoMethodError: undefined method `layout_scene' for #<Java::JavafxStage::Stage:0x7f243900>>
/home/eric/projects/jrubyfx_projects/jrubyfx_web/hello.rb:7:in `start'
org/jruby/RubyBasicObject.java:1691:in `instance_eval'
jar:file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-complete.jar!/jrubyfx/fxml_module.rb:49:in `with'
/home/eric/projects/jrubyfx_projects/jrubyfx_web/hello.rb:6:in `start'
jar:file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-complete.jar!/jrubyfx/java_fx_impl.rb:121:in `launch_app_after_platform'
org/jruby/gen/InterfaceImpl1339899994.gen:13:in `run'

Ignore that I'm probably doing all sorts of horrible things with this code, since it's just experimental, but for whatever reason, in this situation, layout_scene (and perhaps other parts of the DSL, I don't know yet) vanish. The very same java launcher is perfectly capable of launching other far more complex JRubyFX apps, that use FXML and CSS, but toss in layout_scene and it breaks down. Just thought I'd get this in while it was fresh in mind. Thanks. Seems like at some point, scripting existing javafx apps with jrubyfx might be an interesting use case, so thought it would be worth mentioning that this happens.

(Still haven't gotten webstart/jnlp working, but I think I'm starting to get useful errors finally so that's always a good sign).

@byteit101
Copy link
Member

huh, thats odd. are you sure all the files in core_ext are in the jar? Only other suggestion is why are you calling stage.layout_scene(500, 250, :black) ? The with() function makes it implicit: layout_scene(500, 250, :black)

@edubkendo
Copy link
Member Author

Thats actually just code I copied from one of the samples. Except that when I got this error the first few times, I changed it to an explicit call on stage to see if that made a difference which it didn't. Same error. But yeah, definitely checked and the files are in there, including stage.rb where that method is defined.

@byteit101
Copy link
Member

yea I know where it came from, I ported that sample to JRubyFX 😀

hmm, put a puts "hey I was included!" in stage.rb and make sure its called. alternatively, puts file on line 232 of dsl.rb and make sure all extensions are loaded.

@edubkendo
Copy link
Member Author

Hah. Nice work on that, I always thought that was a pretty demo from GroovyFX, ScalaFX, etc. Was happy to see JRubyFX in those brilliant gradients.

So after all our tail-chasing earlier, lol, finally got a chance to look back at this. I added puts "hey I was included!" at the bottom of stage.rb, then for good measure, also went into dsl.rb and added it like this:

    def self.load_dsl
      rt = "#{File.dirname(__FILE__)}/core_ext"
      Dir.glob("#{rt}/*.rb") do |file|
        puts "Before require"                                # See if the block is running at all
        require file
        puts file                                                     # See if the require itself is messing up
      end

Rebuilding the jar and then just using it to run the file works fine, and we get a bunch of output like:

 java -jar jruby-log.jar hello.rb 
Before require
file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-log.jar!/jrubyfx/core_ext/radial_gradient.rb
Before require
file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-log.jar!/jrubyfx/core_ext/drag_event.rb
Before require
...
file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-log.jar!/jrubyfx/core_ext/node.rb
Before require
hey I was included!
...

But when I try using the javafx Launcher again, back to that error:

Exception running Application:
#<NoMethodError: undefined method `layout_scene' for #<Java::JavafxStage::Stage:0x2e61b072>>
/home/eric/projects/jrubyfx_projects/jrubyfx_web/hello.rb:10:in `start'
org/jruby/RubyBasicObject.java:1691:in `instance_eval'
jar:file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-log.jar!/jrubyfx/fxml_module.rb:49:in `with'
/home/eric/projects/jrubyfx_projects/jrubyfx_web/hello.rb:6:in `start'
jar:file:/home/eric/projects/jrubyfx_projects/jrubyfx_web/jruby-log.jar!/jrubyfx/java_fx_impl.rb:121:in `launch_app_after_platform'
org/jruby/gen/InterfaceImpl676239127.gen:13:in `run'

Gotta get some sleep here, but wanted to get this recorded.

BTW, that error was the only output. Nothing from our puts statements.

@edubkendo
Copy link
Member Author

Fixed in PR #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants