gpt4 book ai didi

java - beanshell 新手-运行简单脚本时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:32:27 26 4
gpt4 key购买 nike

我正在尝试在 Beanshell 中运行一个简单的 switch-case 语句

这是我要运行的代码--

temp = assignee.toString();
switch( temp.toString() )
{
case 'missing' : check = "missing"; break;
case '404' : check = "404"; break;
default: check = "data"; break;
}

但我收到以下错误--

 ERROR - Error during script execution: Sourced file: inline evaluation of: ``temp = assignee.toString(); switch( temp.toString() ) { case 'missing' : check = . . . '' Token Parsing Error: Lexical error at line 3, column 8.  Encountered: "i" (105), after : "\'m"
org.webharvest.exception.ScriptException: Error during script execution: Sourced file: inline evaluation of: ``temp = assignee.toString(); switch( temp.toString() ) { case 'missing' : check = . . . '' Token Parsing Error: Lexical error at line 3, column 8.
Encountered: "i" (105), after : "\'m"
at org.webharvest.runtime.scripting.BeanShellScriptEngine.eval(Unknown Source)

我在这里做错了什么?如何解决此错误?

最佳答案

与 Java 一样,BeanShell 中的字符串文字必须使用双引号,而不是单引号:

bsh % x = 'missing';// Error: Error parsing input: bsh.TokenMgrError: Lexical error at line 1, column 37.  Encountered: "i" (105), after : "\'m"bsh % x = "missing";bsh % print(x);missingbsh % 

单引号用于字 rune 字。对多字符字符串使用单引号会导致错误,例如 Encountered: "i"(105), after : "\'m",这是因为 BeanShell 期待另一个 'm 之后(结束字 rune 字),但它得到的是 i

关于java - beanshell 新手-运行简单脚本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12231293/

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