K
K
Koshkasobaka2021-02-02 13:04:47
JavaFX
Koshkasobaka, 2021-02-02 13:04:47

Why does an error occur when running a javafx code?

Hello, I don’t understand why it gives an error, the path to the file is correct. Please help me understand
Code:

package com.example.sudoku;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class SudokuApp extends Application {


    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/com/example/sudoku/fxml/start.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("СУДОКУ");
        stage.setResizable(true);
        stage.show();
    }


    public static void main(String[] args) {
        Application.launch();
    }
}


And the error:

Exception in Application start method
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
  at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
  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.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
  at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
  at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
  at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: 
/C:/Users/1/IdeaProjects/Sudoku/out/production/Sudoku/com/example/sudoku/fxml/start.fxml

  at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
  at com.example.sudoku.SudokuApp.start(SudokuApp.java:14)
  at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
  at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
  at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
  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$4(WinApplication.java:186)
  ... 1 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 1
  at java.lang.String.substring(String.java:1963)
  at com.example.sudoku.logic.hidecells.solvers.ColumnPair.removeDigits(ColumnPair.java:49)
  at com.example.sudoku.logic.hidecells.solvers.ColumnPair.findPairs(ColumnPair.java:30)
  at com.example.sudoku.logic.hidecells.solvers.ColumnPair.tryToSolve(ColumnPair.java:14)
  at com.example.sudoku.logic.hidecells.CellHider.checkSudoku(CellHider.java:99)
  at com.example.sudoku.logic.hidecells.CellHider.selectCell(CellHider.java:62)
  at com.example.sudoku.logic.hidecells.CellHider.makeBoardWithHiddenCells(CellHider.java:24)
  at com.example.sudoku.logic.SudokuGenerator.lambda$fillStorage$0(SudokuGenerator.java:52)
  at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
  at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
  at com.example.sudoku.logic.SudokuGenerator.fillStorage(SudokuGenerator.java:48)
  at com.example.sudoku.logic.Initializer.init(Initializer.java:41)
  at com.example.sudoku.logic.Initializer.getInstance(Initializer.java:30)
  at com.example.sudoku.controller.StartController.initialize(StartController.java:41)
  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
  ... 17 more
Exception running application com.example.sudoku.SudokuApp

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cheypnow, 2021-02-02
@Koshkasobaka

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 1
  at java.lang.String.substring(String.java:1963)
  at com.example.sudoku.logic.hidecells.solvers.ColumnPair.removeDigits(ColumnPair.java:49)
  at com.example.sudoku.logic.hidecells.solvers.ColumnPair.findPairs(ColumnPair.java:30)
  at com.example.sudoku.logic.hidecells.solvers.ColumnPair.tryToSolve(ColumnPair.java:14)

Somewhere substring is called on an empty string. From the code above, it is not clear what exactly the problem is, but somewhere on the 49th line of the ColumnPair class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question