gpt4 book ai didi

java - 类型不匹配 : cannot convert from Boolean to boolean

转载 作者:行者123 更新时间:2023-11-28 22:05:00 56 4
gpt4 key购买 nike

我得到这个异常:

org.apache.jasper.JasperException: Unable to compile class for JSP

我使用的是 tomcat 5.5.23。

org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 29 in the jsp file: /jsp/general/pos/DoMultiWordFrozen.jspf
Type mismatch: cannot convert from Boolean to boolean
26:
27: item = (ItemType)session.getAttribute("item");
28: id = Integer.parseInt((String)session.getAttribute("id"));
29: newItem = Boolean.valueOf((String)session.getAttribute("newItem"));
30: changeGroup = null;
31:
32: if (!newItem && item.getMultiWordFrozen() != null && id != 0) {
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.compiler.ErrorDispatcher.javacError(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.compiler.JDTCompiler.generateClass(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.compiler.Compiler.compile(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.compiler.Compiler.compile(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.compiler.Compiler.compile(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.JspCompilationContext.compile(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.servlet.JspServletWrapper.service(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.servlet.JspServlet.serviceJspFile(jasper5-compiler-5.5.23.jar.so) org.apache.jasper.servlet.JspServlet.service(jasper5-compiler-5.5.23.jar.so) javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-api-5.5.23.jar.so)

newitem 定义为:

boolean newItem = false;

解决方案:

这是因为我使用了不包括autobxing旧JDK 版本。升级到 jdk 1.6 (或任何 >= 1.5 )后。现在工作正常。

最佳答案

Boolean.valueOf 返回一个 Boolean,而不是一个 boolean - 所以听起来您可能想要:

newItem = Boolean.valueOf((String)session.getAttribute("newItem")).booleanValue();

或者,也许更易读:

String newItemAttribute = (String) session.getAttribute("newItem");
newItem = Boolean.valueOf(newItemAttribute).booleanValue();

我有点惊讶它没有自动为您拆箱,但我想这取决于 Jasper 使用的 Java 编译器版本。

关于java - 类型不匹配 : cannot convert from Boolean to boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8911234/

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