label.setText上的java.lang.reflect.InvocationTargetException

label.setText上的java.lang.reflect.InvocationTargetException,java,javafx,fxml,Java,Javafx,Fxml,我确信我离答案很近,但我再也看不到我的错误了 我正在尝试加载listView的自定义listCell 问题是,当我使用 labelArticle.setText(article.getNewsSite()); 它只是得到下面给出的一个异常。意味着我可以为每个新的列表单元格获取它 控制员: public class ArticleCellController extends ListCell<Article> { @FXML private ImageView ico

我确信我离答案很近,但我再也看不到我的错误了

我正在尝试加载listView的自定义listCell

问题是,当我使用

labelArticle.setText(article.getNewsSite());
它只是得到下面给出的一个异常。意味着我可以为每个新的列表单元格获取它

控制员:

public class ArticleCellController extends ListCell<Article> {
    @FXML
    private ImageView icon;
    @FXML
    private Label labelArticle;
    @FXML
    private Label titleArticle;
    @FXML
    private Label resumeArticle;
    @FXML
    private GridPane gridPane;


    private FXMLLoader mLLoader;

    @Override
    protected void updateItem(Article article, boolean empty) {
        super.updateItem(article, empty);

        if(empty || article == null) {
            setText(null);
            setGraphic(null);
        } else {
            if (mLLoader == null) {
                mLLoader = new FXMLLoader(getClass().getResource("/articleCell.fxml"));
                mLLoader.setController(this);
                try {
                    mLLoader.load();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            labelArticle.setText(article.getNewsSite());
            titleArticle.setText(article.getTitle());
            resumeArticle.setText(article.getSummary());

            // setText(null);
            setGraphic(gridPane);
        }

    }
}
我查过这篇文章 但是我没有忘记取消对
mLLoader.load()的注释

那么有什么可能出错呢

更新: 对于调试器,我在try-catch中遇到了第一个错误:

try {
                    mLLoader.load();
                } catch (IOException e) {
                    e.printStackTrace();
                }

“…”/target/classes/articleCell.fxml:8上的LoadException,我假设它是由缺少的fx:controller生成的。。。但是那是毫无意义的。。。对吗?

我不建议
扩展ListCell
。让
控制器
扩展
列表单元格
对我来说似乎是一个糟糕的做法。最相关的例外通常是最内部的例外;这里是
ArticleCellController
类第46行的
NullPointerException
。这就是问题所在:您的'labelArticle'从未设置。@rzwitserroot,但我不这么认为,因为它必须设置为带有fx:id的fxml模板
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NullPointerException
    at ch.bfh.spacenews/ch.bfh.spacenews.ArticleCellController.updateItem(ArticleCellController.java:46)
    at ch.bfh.spacenews/ch.bfh.spacenews.ArticleCellController.updateItem(ArticleCellController.java:14)
    at javafx.controls/javafx.scene.control.ListCell.updateItem(ListCell.java:478)
    at javafx.controls/javafx.scene.control.ListCell.indexChanged(ListCell.java:337)
    at javafx.controls/javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1742)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1726)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1852)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2755)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1245)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
    at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
    at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1784)
    at javafx.graphics/javafx.scene.Scene$2.preferredSize(Scene.java:393)
    at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
    at javafx.graphics/javafx.stage.Window$12.invalidated(Window.java:1086)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
    at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1174)
    at javafx.graphics/javafx.stage.Window.show(Window.java:1189)
    at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
    at ch.bfh.spacenews/ch.bfh.spacenews.MainFX.start(MainFX.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application ch.bfh.spacenews.MainFX
try {
                    mLLoader.load();
                } catch (IOException e) {
                    e.printStackTrace();
                }