0

This code worked, but now I'm in trouble. I think this is the problem, but idk:

Caused by: javafx.fxml.LoadException: 
 /C:/Users/alex/workspace/FXMLExample/bin/application/login.fxml:10

I don't know / understand what is wrong in these codes. In main just run the scene. » Main.java

package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
 Parent root;
 @Override
 public void start(Stage stage) throws Exception {
 root = FXMLLoader.load(getClass().getResource("login.fxml"));
 Scene scene = new Scene(root, 800, 600);
 stage.setTitle("Login system");
 stage.setScene(scene);
 stage.show();
 }
 public static void main(String[] args) {
 launch(args);
 }
}

» login.fxml, here I think that is the problem

<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane xmlns:fx="http://javafx.com/fxml" fx:controller="fxmlexample.Buton"
 alignment="center" hgap="10" vgap="10" styleClass="root">
 <padding>
 <Insets top="25" right="25" bottom="10" left="25" />
 </padding>
 <Text fx:id="bunvenit" text="Bun venit!" GridPane.columnIndex="0"
 GridPane.rowIndex="0" />
 <Text fx:id="text" text="Logheaza-te folosind datele tale personale:"
 GridPane.columnIndex="0" GridPane.rowIndex="1" GridPane.columnSpan="2" />
 <Label text="Username:" GridPane.columnIndex="0"
 GridPane.rowIndex="2" />
 <TextField fx:id="username" GridPane.columnIndex="1"
 GridPane.rowIndex="2" />
 <Label text="Parola:" GridPane.columnIndex="0" GridPane.rowIndex="3" />
 <PasswordField fx:id="parola" GridPane.columnIndex="1"
 GridPane.rowIndex="3" />
 <HBox spacing="10" alignment="bottom_right" GridPane.columnIndex="1"
 GridPane.rowIndex="5">
 <Button text="Logheaza-te" onAction="#loginButton" />
 </HBox>
 <Text fx:id="eroare" GridPane.columnIndex="1" GridPane.rowIndex="7" />
 <Button text="Am uitat parola" GridPane.columnIndex="0"
 GridPane.rowIndex="8" onAction="#passwordButton" />
 <Button text="Creeaza un cont nou" GridPane.columnIndex="1"
 GridPane.rowIndex="8" onAction="#createAccountButton" />
 <stylesheets>
 <URL value="@application.css" />
 </stylesheets>
</GridPane>

» Buton.java, all buttons actions

package fxmlexample;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public abstract class Buton {
 private static final int SCENE_HEIGHT = 600;
 private static final int SCENE_WIDTH = 800;
 @FXML
 private Text eroare;
 @FXML
 private TextField username;
 @FXML
 private PasswordField parola;
 @FXML
 private Parent root;
 /* loginButton */
 @FXML
 protected void loginButton(ActionEvent event) throws IOException {
 boolean gasit = false;
 try (BufferedReader buf = new BufferedReader(new FileReader("data//in//users.txt"))) {
 String linie;
 gasit = false;
 while ((linie = buf.readLine()) != null) {
 String part[] = linie.split(" ");
 if (username.getText().equals(part[0]) && parola.getText().equals(part[1])) {
 gasit = true;
 }
 }
 } catch (FileNotFoundException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 }
 if (gasit) {
 Parent root = FXMLLoader.load(getClass().getResource("../application/logged.fxml"));
 Scene scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
 Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
 stage.setScene(scene);
 stage.setTitle("Felicitari, te-ai logat cu succes!");
 stage.show();
 } else {
 eroare.setText("Username sau parola incorecta!");
 }
 }
}

» The errors:

Exception in Application start method
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
 at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
 at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication156ドル(Unknown Source)
 at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: 
/C:/Users/alex/workspace/FXMLExample/bin/application/login.fxml:10
 at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
 at javafx.fxml.FXMLLoader.access700ドル(Unknown Source)
 at javafx.fxml.FXMLLoader$ValueElement.processAttribute(Unknown Source)
 at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(Unknown Source)
 at javafx.fxml.FXMLLoader$Element.processStartElement(Unknown Source)
 at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
 at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
 at javafx.fxml.FXMLLoader.load(Unknown Source)
 at application.Main.start(Main.java:15)
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1163ドル(Unknown Source)
 at com.sun.javafx.application.PlatformImpl.lambda$runAndWait176ドル(Unknown Source)
 at com.sun.javafx.application.PlatformImpl.lambda$null174ドル(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.sun.javafx.application.PlatformImpl.lambda$runLater175ドル(Unknown Source)
 at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
 at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
 at com.sun.glass.ui.win.WinApplication.lambda$null149ドル(Unknown Source)
 ... 1 more
Caused by: java.lang.InstantiationException
 at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at java.lang.Class.newInstance(Unknown Source)
 at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source)
 ... 23 more
Exception running application application.Main
asked Jan 7, 2016 at 16:39
3
  • I cannot see the following actions from your FXML file: passwordButton and createAccountButton in your controller class. Either remove them from fxml or add to the controller class. Commented Jan 7, 2016 at 16:41
  • They are there, I accidentally removed them when I pasted the code. Commented Jan 7, 2016 at 16:46
  • Are you sure it worked with this abstract controller, which does not implement javafx.fxml.Initializable interface? Commented Jan 7, 2016 at 16:50

1 Answer 1

1

It clearly says:

java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)

It just cannot instantiate your abstract Buton class. Make it concrete.

answered Jan 7, 2016 at 16:56
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.