javafx webview崩溃成彩色框

时间:2013-11-30 09:26:30

标签: webview javafx

在javafx中使用webview时,它会随机停止渲染并将所有内容切换为随机颜色框。 它向我吐出这个错误

"C:\Program Files\Java\jdk1.7.0_45\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 12.1.6\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_45\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\zipfs.jar;C:\Users\Kodukas\IdeaProjects\Starling Browser\out\production\Starling Browser;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain net.makerimages.starling.src.Main
java.lang.NullPointerException
at com.sun.scenario.effect.impl.prism.ps.PPSDrawable.create(PPSDrawable.java:54)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.createCompatibleImage(PPSRenderer.java:148)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.createCompatibleImage(PPSRenderer.java:62)
at com.sun.scenario.effect.impl.ImagePool.checkOut(ImagePool.java:166)
at com.sun.scenario.effect.impl.Renderer.getCompatibleImage(Renderer.java:118)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.getCompatibleImage(PPSRenderer.java:153)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.getCompatibleImage(PPSRenderer.java:62)
at com.sun.scenario.effect.Effect.getCompatibleImage(Effect.java:491)
at com.sun.webpane.sg.prism.WCGraphicsPrismContext$Layer.<init>(WCGraphicsPrismContext.java:1169)
at com.sun.webpane.sg.prism.WCGraphicsPrismContext$ClipLayer.<init>(WCGraphicsPrismContext.java:1226)
at com.sun.webpane.sg.prism.WCGraphicsPrismContext.setClip(WCGraphicsPrismContext.java:234)
at com.sun.webpane.platform.graphics.GraphicsDecoder.decode(GraphicsDecoder.java:205)
at com.sun.webpane.platform.graphics.WCRenderQueue.decode(WCRenderQueue.java:67)
at com.sun.webpane.platform.WebPage.paint2GC(WebPage.java:661)
at com.sun.webpane.platform.WebPage.paint(WebPage.java:640)
at com.sun.javafx.sg.prism.NGWebView.renderContent(NGWebView.java:71)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:204)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:420)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:117)
at com.sun.javafx.tk.quantum.AbstractPainter.paintImpl(AbstractPainter.java:188)
at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:73)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at com.sun.prism.render.RenderJob.run(RenderJob.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:108)
at java.lang.Thread.run(Thread.java:744)
    java.lang.IllegalStateException: Unbalanced saveState/restoreState
at com.sun.webpane.sg.prism.WCGraphicsPrismContext.dispose(WCGraphicsPrismContext.java:1564)
at com.sun.webpane.sg.prism.WCPageBackBufferImpl.disposeGraphics(WCPageBackBufferImpl.java:32)
at com.sun.webpane.platform.WebPage.paint(WebPage.java:642)
at com.sun.javafx.sg.prism.NGWebView.renderContent(NGWebView.java:71)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:204)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:420)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:117)
at com.sun.javafx.tk.quantum.AbstractPainter.paintImpl(AbstractPainter.java:188)
at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:73)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at com.sun.prism.render.RenderJob.run(RenderJob.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:108)
at java.lang.Thread.run(Thread.java:744)
    java.lang.NullPointerException
at com.sun.scenario.effect.impl.prism.ps.PPSDrawable.create(PPSDrawable.java:54)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.createCompatibleImage(PPSRenderer.java:148)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.createCompatibleImage(PPSRenderer.java:62)
at com.sun.scenario.effect.impl.ImagePool.checkOut(ImagePool.java:166)
at com.sun.scenario.effect.impl.Renderer.getCompatibleImage(Renderer.java:118)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.getCompatibleImage(PPSRenderer.java:153)
at com.sun.scenario.effect.impl.prism.ps.PPSRenderer.getCompatibleImage(PPSRenderer.java:62)
at com.sun.scenario.effect.Effect.getCompatibleImage(Effect.java:491)
at com.sun.webpane.sg.prism.WCGraphicsPrismContext$Layer.<init>(WCGraphicsPrismContext.java:1169)
at com.sun.webpane.sg.prism.WCGraphicsPrismContext$ClipLayer.<init>(WCGraphicsPrismContext.java:1226)
at com.sun.webpane.sg.prism.WCGraphicsPrismContext.setClip(WCGraphicsPrismContext.java:234)
at com.sun.webpane.platform.graphics.GraphicsDecoder.decode(GraphicsDecoder.java:205)
at com.sun.webpane.platform.graphics.WCRenderQueue.decode(WCRenderQueue.java:67)
at com.sun.webpane.platform.WebPage.paint2GC(WebPage.java:661)
at com.sun.webpane.platform.WebPage.paint(WebPage.java:640)
at com.sun.javafx.sg.prism.NGWebView.renderContent(NGWebView.java:71)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:204)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:420)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:117)
at com.sun.javafx.tk.quantum.AbstractPainter.paintImpl(AbstractPainter.java:188)
at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:73)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at com.sun.prism.render.RenderJob.run(RenderJob.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:108)
at java.lang.Thread.run(Thread.java:744)
    java.lang.IllegalStateException: Unbalanced saveState/restoreState
at com.sun.webpane.sg.prism.WCGraphicsPrismContext.dispose(WCGraphicsPrismContext.java:1564)
at com.sun.webpane.sg.prism.WCPageBackBufferImpl.disposeGraphics(WCPageBackBufferImpl.java:32)
at com.sun.webpane.platform.WebPage.paint(WebPage.java:642)
at com.sun.javafx.sg.prism.NGWebView.renderContent(NGWebView.java:71)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:204)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:420)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:201)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:40)
at com.sun.javafx.sg.BaseNode.render(BaseNode.java:1145)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:117)
at com.sun.javafx.tk.quantum.AbstractPainter.paintImpl(AbstractPainter.java:188)
at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:73)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at com.sun.prism.render.RenderJob.run(RenderJob.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:108)
at java.lang.Thread.run(Thread.java:744)

    Process finished with exit code 0

这对我的代码没有任何影响,可以在这里看到:

package net.makerimages.starling.src;

import com.sun.webpane.platform.graphics.WCGraphicsContext;
import com.sun.webpane.sg.prism.WCGraphicsPrismContext;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.control.ToolBar;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode; 
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.web.HTMLEditor;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import net.makerimages.starling.src.window.TopBar;

import java.util.logging.Level;
import java.util.logging.Logger;


public class Main extends Application {
  public static TextField addressBar;
  public static ToolBar toolBar;
  public static Stage stg;
  int height = 25;
public static WebView browser;
public static WebEngine webEngine;


@Override
public void start(Stage primaryStage) throws Exception{

     browser = new WebView();
     webEngine = browser.getEngine();
    toolBar=new ToolBar();
    toolBar.setPrefHeight(height);
    toolBar.setMinHeight(height);
    toolBar.setMaxHeight(height);
    toolBar.getItems().add(new TopBar());
     addressBar=new TextField("Enter a URL");
     addressBar.setId("addressBar");

    Logger logger = Logger.getLogger( WCGraphicsContext.class.getName() );
    logger.setLevel( Level.OFF);


    addressBar.setOnKeyPressed( new EventHandler<KeyEvent>() {
        public void handle(final KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.ENTER) {
                loadWebsite(addressBar.getText());

                keyEvent.consume();
            }
        }
    });






    BorderPane root=new BorderPane();
    primaryStage.initStyle(StageStyle.UNDECORATED);
    primaryStage.getIcons().add(new Image("url:http://www.iconshock.com/img_jpg/SUNNYDAY/animals/jpg/32/starling_bird_icon.jpg"));
    primaryStage.setTitle("Starling Browser");
    primaryStage.setScene(new Scene(root, 800, 700));
    root.setBottom(addressBar);
    root.setAlignment(addressBar, Pos.BOTTOM_CENTER);
    root.setCenter(browser);


    root.getStylesheets().add(this.getClass().getResource("starlingElements.css").toExternalForm());
   root.setTop(toolBar);


    primaryStage.show();
    webEngine.load("http://www.google.com");

    stg=primaryStage;
}


public static void main(String[] args) {
    launch(args);
}

 public static void loadWebsite(String url)
 {
    webEngine.load("http://"+ url);

 }
}

我没有想让它停下来,有人能帮忙吗?

1 个答案:

答案 0 :(得分:0)

1.7.0u40上运行时,我看不到闪烁。你可以试试

  • 在JDK 8 EA上运行它以确保这是JDK 7特定问题。
  • 删除样式表(我删除了这一行以使其可以运行)。
  • 删除TopBar导入以查看是否是原因(我没有,所以我删除了这一行)。