Sandip Armal Patil
Sandip Armal Patil

Reputation: 5905

getting exception while opening custom popup on mouse click

I have one package name com.soarite which containing SOARiteController class and two fxml file like soaritemain.fxml and custom_control.fxml.

I have one tree in soaritemain.fxml. I am trying to show popup on mouseclick on that tree. or want to show only two menu.

Here is my code.

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/soarite/custom_control.fxml"));
    //fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);
    fxmlLoader.setLocation(null);
    try {
        fxmlLoader.load();
    }
    catch(Exception e)
    {
    }

And here is my custom_control.fxml.

<AnchorPane id="AnchorPane" minHeight="119.5" prefHeight="119.5" prefWidth="188.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="com.soarite.SOARiteController">
<children>
<VBox layoutX="33.0" layoutY="35.0" prefHeight="73.0" prefWidth="100.0">
  <children>
    <Button fx:id="treeOpenTestBed" mnemonicParsing="false" onAction="#handleOpenTestBedTree" text="Open TestBed" />
    <Button fx:id="treeNewTestBed" mnemonicParsing="false" onAction="#handleNewTestBedTree" text="New TestBed" />
  </children>
</VBox>
</children>
<stylesheets>
<URL value="@main.css" />
</stylesheets>
</AnchorPane>    

Here exception details which i am getting.

Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2021)
at com.soarite.SOARiteController.MouseClickedOnTree(SOARiteController.java:224)   

I don't understand how to do this. Is this i am doing right or e need to do something else. I am newbie on JavaFx.

Upvotes: 0

Views: 111

Answers (1)

James_D
James_D

Reputation: 209553

fxmlLoader.setLocation(null);

is causing the exception you see. The location is the resource representing the fxml file which is to be loaded; so if you set it to null the loader doesn't know where to find the file. Remove this line.

This will give you another exception. You are also setting the controller "by hand" with the line

fxmlLoader.setController(this);

and then your fxml file itself specifies a controller with the fx:controller attribute in the root element. You cannot specify a controller in fxml if the controller is already set on the FXMLLoader. You probably want to remove the setController(...) call in the Java code.

Upvotes: 1

Related Questions