CellValueFactory抛出nullPointerException

时间:2019-01-27 22:46:12

标签: javafx nullpointerexception

每次从GUI调用方法时,CellValueFactory都会引发NullPointetrException(NPE)。

我从嵌入式Derby DB中读取数据并将其转换为TableView-至少这是目标。 我已经抓到了NPE,控制台提供了以下输出:

原因:null消息:null StackTrace:[Ljava.lang.StackTraceElement; @ 79daf03c

我还检查了StringPropertys,它们不为零。这是一个,但是我检查了每一行:

StringProperty [值:170] StringProperty [值:Höhlenkrieger] StringProperty [值:null]

    @FXML
    // liegt auf test2, muss auf Optionen!

    private void ladeTabelle() {

    try {
        SQLConnection.createDatabaseConnection("test35");

        //Zeile 63 ist das Problem!
        subfactionCol.setCellValueFactory(cellData
                -> cellData.getValue().subfactionProperty());
        nameCol.setCellValueFactory(cellData
                -> cellData.getValue().nameProperty());
        pointValCol.setCellValueFactory(cellData
                -> cellData.getValue().pointvalueProperty());
    }// end initialize() 
    catch (NullPointerException npe) {
        System.out.println("Cause: " + npe.getCause()
    + "\t Message:   "+npe.getMessage()
        + "\t StackTrace: " + npe.getStackTrace()
        );
    }
}

以及产生StringProperties的代码

        StatCard sC = new StatCard(name, faction, subfaction, unit_type, number_of_elements,
                    pointvalue, units_in_collection, movementPoints, movemntOrderH, movemntOrderS,
                    movemntOrderA, movemntOrderH, maneuvers, initiative, skillMelee, skillRange,
                    attack1Name, attack1, attack2Name, attack2, attackMissileName, attackMissileRangeShort,
                    attackMissileRangeLong, attack_bonus, overrun, size, armor_melee, armorRange, hitpoints,
                    fear, moraleBreak, moraleRage, banner, musician, artilleryType, ballistic_range_short,
                    ballistic_range_medium, ballistic_range_long, magic_points, commandPoints, controlArea,
                    commandstars, special_rules);


            SQLdataList.add(sC);
        }
    } catch (ClassNotFoundException | SQLException e) {
        System.out.println("Fehler! exception. Cause: " + e.getCause() + "\n" + "\n"
                + "Message ist: " + e.getMessage());
    }

    SQLdataList_observable = FXCollections.observableArrayList(SQLdataList);

    for (StatCard sC : SQLdataList_observable) 
    {

        System.out.println(sC.pointvalueProperty().toString() 
                + sC.nameProperty().toString() 
                + sC.subfactionProperty().toString());
    }

StringPorperties在StatCard类中:

public SimpleStringProperty subfactionProperty() 
{
    return new SimpleStringProperty(subfaction);
}        

public SimpleStringProperty nameProperty() 
{
    return new SimpleStringProperty(name);
}

public SimpleStringProperty pointvalueProperty() 
{
    return new  SimpleStringProperty(Integer.toString(pointvalue));
}

我已经广泛地搜索了这个问题,但是到目前为止,我还没有找到解决方案。我无法弄清楚为什么cellFactory会给出零,即eben,所以StringProperties不会。

有什么想法可以尝试吗?

0 个答案:

没有答案