gpt4 book ai didi

JavaFX WebEngine 生成 StringIndexOutOfBoundsException,出了什么问题?

转载 作者:行者123 更新时间:2023-12-02 13:11:08 39 4
gpt4 key购买 nike

我有一个使用 JavaFX 的小实验项目,其中有一个按钮和一个 WebView。按下按钮时,将加载网站:

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.web.WebView;

public class Controller {
@FXML private Button theButton;
@FXML private WebView theWebView;


@FXML
protected void loadWebSite(ActionEvent event) {
theWebView.getEngine().load("https://dashman.tech");
}
}

发生这种情况时,我会收到以下错误:

java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.substring(String.java:1963)
at com.sun.javafx.webkit.prism.WCGraphicsPrismContext.drawString(WCGraphicsPrismContext.java:960)
at com.sun.webkit.graphics.GraphicsDecoder.decode(GraphicsDecoder.java:290)
at com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:91)
at com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:102)
at com.sun.webkit.graphics.WCImage.flushRQ(WCImage.java:52)
at com.sun.javafx.webkit.prism.RTImage.lambda$getPixelBuffer$77(RTImage.java:163)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:745)
java.lang.StringIndexOutOfBoundsException: String index out of range: 7
at java.lang.String.substring(String.java:1963)
at com.sun.javafx.webkit.prism.WCGraphicsPrismContext.drawString(WCGraphicsPrismContext.java:960)
at com.sun.webkit.graphics.GraphicsDecoder.decode(GraphicsDecoder.java:290)
at com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:91)
at com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:102)
at com.sun.webkit.graphics.WCImage.flushRQ(WCImage.java:52)
at com.sun.javafx.webkit.prism.RTImage.lambda$getPixelBuffer$77(RTImage.java:163)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:745)
java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.substring(String.java:1963)
at com.sun.javafx.webkit.prism.WCGraphicsPrismContext.drawString(WCGraphicsPrismContext.java:960)
at com.sun.webkit.graphics.GraphicsDecoder.decode(GraphicsDecoder.java:290)
at com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:91)
at com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:102)
at com.sun.webkit.graphics.WCImage.flushRQ(WCImage.java:52)
at com.sun.javafx.webkit.prism.RTImage.lambda$getPixelBuffer$77(RTImage.java:163)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:745)

有什么想法吗?我该如何预防?该网站似乎加载良好。其他网站不会生成这些错误。

最佳答案

当我在 Mac OSX 上使用 jdk1.8.0_131 进行测试时,我得到了一个略有不同的错误,其中使用了堆栈上的 native 方法的不同堆栈:

Exception in thread "JavaFX Application Thread" java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.substring(String.java:1963)
at com.sun.javafx.webkit.prism.WCFontImpl.getGlyphsAndAdvances(WCFontImpl.java:120)
at com.sun.webkit.network.URLLoader.twkDidReceiveData(Native Method)
at com.sun.webkit.network.URLLoader.notifyDidReceiveData(URLLoader.java:844)
at com.sun.webkit.network.URLLoader.lambda$didReceiveData$102(URLLoader.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

当我将com.sun.javafx.webkit.prism.WCFontImpl的日志记录级别设置为全部时,我得到以下信息:

c.sun.javafx.webkit.prism.WCFontImpl - str='ð' (length=2), from=0, to=4, rtl=false
c.sun.javafx.webkit.prism.WCFontImpl - str='ð©' (length=4), from=0, to=7, rtl=false
c.sun.javafx.webkit.prism.WCFontImpl - str='ð' (length=3), from=0, to=6, rtl=false

当我查看字符串时,日志消息中的长度似乎是正确的字符数,但 fromto 的参数似乎不采用考虑到字符串包含多字节字符。这些错误的值用于子字符串调用,然后导致异常。我无法找出哪种字体在这里造成麻烦。

所以我认为,该网站加载了一些已损坏或不正确的字体。浏览器引擎会忽略这些错误,尽管会转储堆栈跟踪,这就是页面仍然可以工作的原因 - 也许没有以所需的字体显示某些内容。

为什么你有不同的堆栈跟踪?我不确定,这可能是因为您使用不同的操作系统或不同的 Java 版本?

而且我认为您无法阻止这种情况,除非您对该网站负责并检查所使用的字体。

关于JavaFX WebEngine 生成 StringIndexOutOfBoundsException,出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43953096/

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