gpt4 book ai didi

java - EL1012E : Cannot index into a null value

转载 作者:行者123 更新时间:2023-12-02 11:06:43 40 4
gpt4 key购买 nike

我在 Thymeleaf 模板中有这段代码

var theList = /*[[${route}]]*/

for (i = 0; i < theList.length; i++) {
var coordinate = [ /*[[${theList[i].longitude}]]*/ , /*[[${theList[i].latitude}]]*/ ];
coordinates2.push(coordinate);
}

当对象${route}不为空,而是我通过 Controller 传递的空列表时:

List<Coordinate> route = new ArrayList<Coordinate>();
model.addAttribute("route", route);

我收到此错误:

org.springframework.expression.spel.SpelEvaluationException: EL1012E: Cannot index into a null value
at org.springframework.expression.spel.ast.Indexer.getValueRef(Indexer.java:132)
at org.springframework.expression.spel.ast.Indexer.getValueInternal(Indexer.java:89)
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:57)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:121)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:324)

最佳答案

您不能混合 JavaScript 和 Thymeleaf 变量。变量iJavaScript for 循环 ( for (i = 0; i < theList.length; i++) ) 中定义,但您尝试在 Thymeleaf 表达式中使用它。您需要将它们分开。

var theList = /*[[${route}]]*/ [];

for (i = 0; i < theList.length; i++) {
var coordinate = [theList[i].longitude, theList[i].latitude];
coordinates2.push(coordinate);
}

关于java - EL1012E : Cannot index into a null value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50906348/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com