启动一个应用程序并通过其他类与之交谈(在启动时尚未实例化),我想构建具有多个窗口和Thread相互交互的多应用程序。
我将用不太笼统的问题来解释我的问题。我有“ ApplicationPane”应用程序1:如何使用对象参数实例化GUI?这是问题的第一部分。通常,当我在一个项目上时,我自然会有一个前端(这里是JavaFX GUI)和一个后端(一个或一个由对象“后端”引用的线程)。
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();
}
问题似乎是new ApplicationPane()
似乎是null
或开始时创建的画布是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();
答案 0 :(得分:0)
嗯,我现在了解的是,无法使用new关键字创建应用程序。我在start(Stage)方法中放置了一个任务,以创建到其他线程的链接。