Java setText()引发空指针异常,但元素不是空的

Java setText()引发空指针异常,但元素不是空的,java,htmlunit,Java,Htmlunit,因此,我试图在HtmlUnit中设置元素的文本,但由于某些原因,我不太明白是否抛出了NullPointerException。显然,该元素存在于页面上,它是由htmlunit找到的!那么为什么setText会抛出错误呢?有什么想法吗 代码: 输出: HtmlTextInput[<input type="text" required="" id="gc-redemption-input" name="claimCode" class="gc-redemption-input a-input-

因此,我试图在HtmlUnit中设置元素的文本,但由于某些原因,我不太明白是否抛出了NullPointerException。显然,该元素存在于页面上,它是由htmlunit找到的!那么为什么setText会抛出错误呢?有什么想法吗

代码:

输出:

HtmlTextInput[<input type="text" required="" id="gc-redemption-input" name="claimCode" class="gc-redemption-input a-input-text a-span12 a-form-selected" autofocus="autofocus" value="">]

问题可能是
stringcode='123'
,因为它在我的IDE中显示以下错误:
未关闭的字符文字
。请尝试使用双引号:
stringcode=“123”

谢谢你的精彩捕捉!不幸的是,这不是问题所在,这是一行我没有抄过来,而是打出来的:)现在应该解决了。看见
HtmlTextInput[<input type="text" required="" id="gc-redemption-input" name="claimCode" class="gc-redemption-input a-input-text a-span12 a-form-selected" autofocus="autofocus" value="">]
Exception in thread "main" 
java.lang.NullPointerException
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.hasTopCall(ScriptRuntime.java:3241)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:102)
    at com.gargoylesoftware.htmlunit.javascript.host.dom.MutationObserver.attributeReplaced(MutationObserver.java:165)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:348)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireHtmlAttributeReplaced(HtmlElement.java:353)
    at com.gargoylesoftware.htmlunit.html.HtmlElement.setAttributeNS(HtmlElement.java:209)
    at com.gargoylesoftware.htmlunit.html.HtmlInput.setAttributeNS(HtmlInput.java:538)
    at com.gargoylesoftware.htmlunit.html.HtmlTextInput.setAttributeNS(HtmlTextInput.java:164)
    at com.gargoylesoftware.htmlunit.html.DomElement.setAttribute(DomElement.java:331)
    at com.gargoylesoftware.htmlunit.html.HtmlInput.setValueAttribute(HtmlInput.java:94)
    at com.gargoylesoftware.htmlunit.html.HtmlTextInput.setText(HtmlTextInput.java:124)