一、问题描述

在JAVA FX中使用jxbrowser,第一次打开一个窗口,然后又打开一个窗口就出现如下错误:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetExceptionat javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)at javafx.event.Event.fireEvent(Event.java:198)at javafx.scene.Node.fireEvent(Node.java:8413)at javafx.scene.control.Button.fire(Button.java:185)at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)at javafx.event.Event.fireEvent(Event.java:198)at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)at java.security.AccessController.doPrivileged(Native Method)at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)at com.sun.glass.ui.View.handleMouseEvent(View.java:555)at com.sun.glass.ui.View.notifyMouse(View.java:937)at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)... 48 more
Caused by: javafx.fxml.LoadException:
/D:/xxxx/xxxx/analysis/target/classes/jxbrowser.fxmlat javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)at com.fendo.analysis.AnalysisController.openJxBrowser(AnalysisController.java:251)... 58 more
Caused by: com.teamdev.jxbrowser.chromium.BrowserException: The Chromium profile directory is already used/locked by another BrowserContext instance or process.at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:216)at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:184)at com.teamdev.jxbrowser.chromium.Browser.<init>(SourceFile:151)at com.fendo.analysis.jxbrowser.JxBrowserController.initialize(JxBrowserController.java:51)at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)... 66 more

代码如下:

BrowserContextParams params = new BrowserContextParams("D:\\IDEA_work\\javafx\\jxbrowser\\cookie");
BrowserContext context = new BrowserContext(params);Browser browser = new Browser(context);
BrowserView view = new BrowserView(browser);JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);browser.loadURL("https://www.baidu.com");
CookieStorage cookieStorage = browser.getCookieStorage();// Create and add new cookie
int oneHourInMilliseconds = 36000000;
int microsecondsOffset = 1000;
// Cookie will be alive during one hour starting from now
long expirationTimeInMicroseconds = (System.currentTimeMillis() +oneHourInMilliseconds) * microsecondsOffset;
//        cookieStorage.setCookie("http://www.baidu.com", "mycookie", "myvalue",
//                ".baidu.com", "/", expirationTimeInMicroseconds, false, false);
List<Cookie> cookies = cookieStorage.getAllCookies();
for (Cookie cookie : cookies) {System.out.println("cookie = " + cookie);
}

二、解决方法

这是由于浏览器使用相同配置文件目录造成的,也就是上面的BrowserContext,多次初始化时,使用的都是BrowserContext这一个用的是同一个目录。官网提供了一个解决方法:https://jxbrowser.support.teamdev.com/support/solutions/articles/9000012878-creating-browser

多个窗口浏览时,初始化Browser时使用不同的目录就行了。

jxbrowser错误The Chromium profile directory is already used/locked by another BrowserContext instance相关推荐

  1. JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can‘t find profile directory

    报错信息 JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile direc ...

  2. 记录使用IDEA部署Tomcat时提示错误:the selected directory is not a TomEE home

    使用IDEA部署Tomcat时提示错误:the selected directory is not a TomEE home 原因 : 选择错误 解决方案: 移除TomcatEE Server 添加T ...

  3. kinit: Included profile directory could not be read while initializing Kerberos 5 library

    为什么80%的码农都做不了架构师?>>>    查看/etc/krb5.conf下的includedir是否存在 转载于:https://my.oschina.net/aubao/b ...

  4. LogStash 错误:Logstash could not be started because there is already another instance usin

    $ ./bin/logstash -f ./myconfig/conf.conf 错误提示: Sending Logstash logs to /usr/local/logstash/logstash ...

  5. Vue错误03:Property or method “xxx“ is not defined on the instance but referenced during render.

    问题描述 根据已有数据,动态生成一个选择器,但在设置了以后无法正常渲染如下: 同时,控制台报错: 组件里面的代码如下: js代码: 问题解决: 定义v-for的时候,表达式"x in obj ...

  6. 如何解决常见的 Active Directory 复制错误

    如何解决常见的 Active Directory 复制错误 Windows Server 2019 Windows Server 2016 Windows Server 2012 R2 Standar ...

  7. Chromium浏览器(CEF)的命令行列表说明

    找到的Chromium浏览器的命令行说明列表,转放在这里以方便查看. List of Chromium Command Line Switches There are lots of command ...

  8. Chromium命令行开关列表2

    Chromium命令行开关列表 Google Chrome浏览器可以使用很多命令行. 一些更改功能的行为,其他用于调试或试验. 该页面列出了可用的开关,包括其条件和说明. 上一次自动更新发生在2020 ...

  9. Linux安装软件时的错误解决

    一. 问题描述: ubuntu使用"apt-get install"安装程序时遇到错误提示 you might want to run 'apt-get -f install' t ...

  10. jboss启动常见的错误

    jboss启动常见的错误 1.报错:java.rmi.server.ExportException: Port already in use: 1098; nested exception is:   ...

最新文章

  1. benchmarksql测试mysql_数据库压力测试工具 -- BenchmarkSQL 使用说明
  2. MIT提出Liquid机器学习系统,可像液体一样适应动态变化
  3. python 报错 bs4 FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml
  4. Android fingerprint指纹/face人脸代码导读
  5. 【客户下单】后台系统自动分单成功生成工单发送短信
  6. [C++] 用Xcode来写C++程序[3] Constants
  7. 商女不知亡国恨,一天到晚敲代码
  8. 计算机大学一个专业几个班,2016年兰州大学计算机类(含基地班、计算机科学与技术等4个专业)专业最低分是多少?...
  9. Ubuntu下配置Window CIFS共享
  10. Python机器学习方向企业面试题(三)
  11. Struts2入门这一篇就够了 1
  12. hdu 4417 树状数组查询区间不是1到n时需要转换,例[0,5]变成[1,6]
  13. 深入解析字符串的比较方法:“==”操作符;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。...
  14. MapReduce计算框架知识总结(一)
  15. 2015最新Linkedin人才趋势报告
  16. python如何输出结果到txt_python 执行结果输出为txt
  17. java将Word转换成PDF三种方法
  18. [c++]小数处理ceil, floor, round
  19. Partitioning big graph with respect to arbitrary proportions in a streaming manner 菜鸟解读
  20. 冉宝的每日一题-8月16日回溯法+ 动态规划压缩

热门文章

  1. ubuntu1604安装网卡驱动 联想g510
  2. ubuntu libxml2 使用
  3. mysql 判断语句_mysql条件判断语句讲解
  4. IIS开启了GZIP和XCACHE之后飞快
  5. android 框架作用是什么意思,Android系统上的Xp框架有什么用
  6. 2019春运购票指南 “盘”票不易 回家过年的票你买到了吗
  7. Vue经典开源项目汇总
  8. 用户故事(二):为什么要使用用户故事表达需求?
  9. 等价类划分法设计用例(超详细)
  10. 通过更改cmake的源码实现使用代理的下载命令