Исключение Nullpointer для setText JavaFX - PullRequest
0 голосов
/ 04 мая 2020

Я получаю исключение NullPointer, когда пытаюсь установить текст на экране.

Прежде чем все скажут мне провести какое-то исследование, я попробовал решение по этому вопросу:

SetText Исключение нулевого указателя

Который я забыл добавить к своему @ F XML над созданием метки, но это ничего не изменило

Вот мой код .

public class ReadScreenController implements Initializable {

    private ArrayList<String> book;

    @FXML
    private Label label;
    private int currentPage;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
           book = new ArrayList<>();
           book.add("The Old Man and the Sea By Ernest Hemingway\n To Charlie Shribner And To Max Perkins\n He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish. In the first forty days a boy had been with him. But after forty days without a fish the boy’s parents had told him that the old man was now definitely and finally salao, which is the worst form of unlucky, and the boy had gone at their orders in another boat which caught three good fish the first week");
           String line = book.get(0);
           System.out.println(line);
           label.setText(line);
           currentPage = 1;
    }

Вот моя ошибка

Caused by: java.lang.NullPointerException
    at calibre.ReadScreenController.initialize(ReadScreenController.java:81)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)

В строке 81 я установил текст

С уважением

...