0

I found similar problem here but the solution for that didn't resolve my problem. The link for the similar problem is here enter link description here. Well about my problem, progressbar won't update when I click on the radio button.

my fxml file for that scene is here

 <?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>

My controller class

In this class i am setting progress to my bar and its trowing me null pointer exception, i really cant find where the problem is so i need you help.

   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) {  
 }
}

The error code i am gettig is here :

   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

So if someone could help, i would be thankful, if you need some more material just ask.

Milos
  • 87
  • 1
  • 9

1 Answers1

0

You are facing the error at this line

pb.setProgress(0.1);

Because your ProgressBar is null. You have to initialize ProgressBar before using the object of ProgressBar.

Fazal Hussain
  • 1,129
  • 12
  • 28