使用了groovy和java 我有用于吐痰的groovy脚本,
def msgO = app.getConversation()
msgO+=msg.getText()
def list = msgO.split("\\+")
何时收到错误 使用java代码运行:
CaptureUtil captureUtil = new CaptureUtil();
binding.setVariable("cap", captureUtil);
GroovyShell shell = new GroovyShell(binding);
boolean status = (boolean) shell.evaluate(template);
得到错误:
java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0
+
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.sequence(Pattern.java:2123)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at java.lang.String.split(String.java:2380)
at java.lang.String.split(String.java:2422)
at java_lang_String$split.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at Script1.run(Script1.groovy:20)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at com.ctf.sims.parseutils.CaptureUtil.parseGroovy(CaptureUtil.java:185)
运行groovy脚本时运行良好,仅在运行java时出错。
答案 0 :(得分:0)
您可以尝试使用
msgO.split(Pattern.quote('+'))