我在这里发现了类似的问题,但解决方法并没有解决我的问题。 类似问题的链接在enter link description here。 关于我的问题,当我点击单选按钮时,进度条不会更新。
该场景的fxml文件在这里
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="468.0" prefWidth="972.0" style="-fx-
background-color: #02b496;" xmlns="http://javafx.com/javafx/9.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="Controllers.RegisterController">
<children>
<ImageView fitHeight="497.0" fitWidth="972.0" opacity="0.68" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@LogInPic.jpg" />
</image>
</ImageView>
<AnchorPane id="registration" fx:id="registration" layoutX="544.0" layoutY="49.0" opacity="0.91" prefHeight="357.0" prefWidth="359.0" style="-fx-background-color: orange;">
<children>
<Text layoutX="94.0" layoutY="44.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Sign Up" textAlignment="CENTER" wrappingWidth="133.5869140625">
<font>
<Font size="18.0" />
</font>
</Text>
<Text layoutX="30.0" layoutY="107.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome to register pane " wrappingWidth="189.13671875">
<font>
<Font size="14.0" />
</font>
</Text>
<RadioButton fx:id="menadzer" layoutX="30.0" layoutY="195.0" mnemonicParsing="false" onAction="#handleMenadzerBtn" text="Manager" />
<RadioButton fx:id="kupac" layoutX="161.0" layoutY="195.0" mnemonicParsing="false" onAction="#handleKupacBtn" text="Customer" />
<Text layoutX="30.0" layoutY="146.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Before you start registration choose one of the following" wrappingWidth="226.283203125">
<font>
<Font size="14.0" />
</font>
</Text>
<Text layoutX="30.0" layoutY="257.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Registartion procces completion">
<font>
<Font size="14.0" />
</font>
</Text>
<Button layoutX="246.0" layoutY="270.0" mnemonicParsing="false" onAction="#handleBackBtn" prefHeight="17.0" prefWidth="92.0" style="-fx-background-color: #df8020;" text="Back">
<font>
<Font size="15.0" />
</font>
</Button>
<ProgressBar fx:id="pb" layoutX="30.0" layoutY="273.0"
opacity="0.57" prefHeight="24.0" prefWidth="200.0" progress="0.0" />
</children>
</AnchorPane>
</children>
</AnchorPane>
我的控制器类
在这个课程中,我正在设置进度到我的酒吧并且它向我扔了空指针异常,我真的无法找到问题所在,所以我需要你的帮助。
public class RegisterController implements Initializable {
@FXML
private ProgressBar pb;
@FXML
private void handleMenadzerBtn(ActionEvent event) throws IOException {
pb.setProgress(0.1);
long mTime = System.currentTimeMillis();
long end = mTime + 2000;
while (mTime < end) {
mTime = System.currentTimeMillis();
}
Parent root = FXMLLoader.load(getClass().getResource("/View/Home.fxml"));
Scene scene = new Scene(root);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setTitle("JavaFX and Maven");
window.setScene(scene);
window.show();
}
/**
* Initializes the controller class.
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
错误代码我是gettig在这里:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.ToggleButton.fire(ToggleButton.java:256)
at javafx.scene.control.RadioButton.fire(RadioButton.java:113)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 49 more
Caused by: java.lang.NullPointerException
at Controllers.RegisterController.handleMenadzerBtn(RegisterController.java:41)
... 59 more
Feb 13, 2018 4:19:42 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX
runtime of version 8.0.101
所以,如果有人可以提供帮助,我会很感激,如果你需要更多的材料,请问。
答案 0 :(得分:0)
您正面临此行的错误
pb.setProgress(0.1);
因为ProgressBar为null。在使用ProgressBar的对象之前,必须初始化ProgressBar。