-2

Launch an application and talk to it via other classes (not instanciated at the moment of launching) I want to build multi app with multiple windows and Thread interacting one by one.

I will explain my problem with not too general question. I have "ApplicationPane" Application 1 : how to instantiate the GUI with object arguments? That is the first part of the question. In general when I'm on a project, I have naturally a frontend (here the JavaFX GUI) and a backend (one or sevaral thread referenced by a Object "Backend".

public static void main(String... args) {

    SampleDrawingProcessor sampleDrawingProcessor = new SampleDrawingProcessor();


    Oscillator os1 = new Oscillator(440, SoundProductionSystem.Waveform.SIN);

    os1.getOutProcessors().put("Drawing samples", sampleDrawingProcessor);


    ApplicationPane applicationPane = new ApplicationPane(sampleDrawingProcessor);


    os1.start();

    sampleDrawingProcessor.start();

}
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
 at be.manudahmen.mylittlesynth.processor.AudioViewer.render(AudioViewer.java:71)
 at be.manudahmen.mylittlesynth.processor.AudioViewer$CanvasRedrawTask.handle(AudioViewer.java:201)
 at javafx.animation.AnimationTimer$AnimationTimerReceiver.lambda$handle$485(AnimationTimer.java:57)
 at java.security.AccessController.doPrivileged(Native Method)
 at javafx.animation.AnimationTimer$AnimationTimerReceiver.handle(AnimationTimer.java:56)
 at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:357)
 at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
 at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:514)
 at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:498)
 at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:491)
 at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$403(QuantumToolkit.java:319)
 at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
 at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
 at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
 at java.lang.Thread.run(Thread.java:748)
public static void testOscillator() {
    ApplicationPane.main();
}

public static void main(String ... args)
{
    ApplicationPane applicationPane = new ApplicationPane();

    SampleDrawingProcessor sampleDrawingProcessor = new SampleDrawingProcessor(applicationPane);

    Oscillator os1 = new Oscillator(440, SoundProductionSystem.Waveform.SIN);
    os1.getOutProcessors().put("Drawing samples", sampleDrawingProcessor);
    os1.start();

    sampleDrawingProcessor.start();
}

The problem seems to be Application reference after new ApplicationPane() seems to be null or the canvas created in start is null.

   if(app==null)
        System.exit(-1);
    Canvas drawingZone = app.
            getDrawingZone();
    if(drawingZone==null)
        System.exit(-2);
    GraphicsContext context2D = drawingZone.getGraphicsContext2D();
"C:\Program Files\Java\jdk1.8.0_171\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.6\lib\idea_rt.jar=57668:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.6\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_171\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_171\lib\javafx-mx.jar;C:\Users\Win\IdeaProjects\MyLittleSynth\out\production\MyLittleSynth;C:\Users\Win\IdeaProjects\MyLittleSynth\lib\empty3-64.jar;C:\Users\Win\IdeaProjects\MyLittleSynth\lib\xuggler-3.4.jar" be.manudahmen.mylittlesynth.processor.apps.ApplicationPane

Process finished with exit code -2
    GraphicsContext context2D = drawingZone.getGraphicsContext2D();
fabian
  • 80,457
  • 12
  • 86
  • 114
Obi Two
  • 1
  • 1
  • 5
  • 1
    It is not clear to me what you are asking. Is the question "How do I pass arguments to GUI controllers?"? If so - what stops you from having a constructor with the required parameters in `ApplicationPane` (which I assume is your own class)? If the question is how to access and update the UI from a background thread see e.g. [this question](https://stackoverflow.com/questions/13784333/platform-runlater-and-task-in-javafx). – Itai Aug 26 '18 at 07:16
  • In fact I'd like the model of application (work code) be not too dependent of JavaFX. – Obi Two Aug 26 '18 at 07:37
  • Please provide a [mcve] that demonstrates the problem. – kleopatra Aug 26 '18 at 10:35
  • There are a short sample of classes. – Obi Two Nov 06 '18 at 14:52
  • There are a short sample of classes. I was asking how can I succeed with my project while implementing a more convenient API within the application (easy-to-read code, and working program, and "perfomance affordable value"??) My code resides here: https://gitlab.com/Graphics3D/MyLittleSynth/tree/newmaster/src/main/java/be/manudahmen/mylittlesynth/processor – Obi Two Nov 06 '18 at 15:18

1 Answers1

0

Well, what I understand now, is that an application can't be created with the new keyword. I put a task in start(Stage) method creating links to other threads.

Obi Two
  • 1
  • 1
  • 5