Java Desktop.browse偶尔会返回“在任何活动的激活上下文中找不到请求的查找密钥”。 [英] Java Desktop.browse occasionally returning "requested lookup key not found in any active activation context"

查看:554
本文介绍了Java Desktop.browse偶尔会返回“在任何活动的激活上下文中找不到请求的查找密钥”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的在努力解决这个问题,因为它似乎随机发生在我身上。当我打电话时,

I am really struggling with this issue as it seems to occur randomly for me. When I call,

Desktop.browse(some url);

Internet Explorer不会显示。异常消息如下,

Internet Explorer will not display. The exception message is as follows,


在任何活动的激活上下文中找不到请求的查找键。

The requested lookup key was not found in any active activation context.

当它发生时,它会一直发生,直到我重新启动机器,但最终会再次发生。

When it occurs it occurs consistently until I restart the machine, but it eventually occurs again.

工作站似乎有这个问题的是运行Windows XP,将Internet Explorer 8设置为默认浏览器。

The workstations that seem to have this problem are running Windows XP with Internet Explorer 8 set as the default browser.

编辑:我忘了提及如果我直接打开Internet Explorer导航到相关的URL然后它将正常工作。

I forgot to mention that if I open up Internet Explorer directly and navigate to the URL in question then it will work fine.

EDIT2:如果调用Desktop.browse然后至少15分钟后再次调用它,这似乎会发生。现在重新启动应用程序似乎解决了这个问题。

This seems to happen if Desktop.browse is invoked and then is called again at least 15 minutes later. Restarting the application now seems to fix the problem.

推荐答案

我缩小了问题并发现了什么是真正导致这个问题,它有毕竟与时间无关。

I narrowed down the problem and discovered what was TRULY causing this, it had nothing to do with the time after all.

java.awt.Desktop.browse(some url); 抛出此错误是因为在应用程序的上一步中,使用JACOB框架以编程方式打开了ActiveXObject。

java.awt.Desktop.browse("some url"); was throwing this error because in a previous step in the application an ActiveXObject was opened programmatically using the JACOB framework.

使用此ActiveXObject编写此代码的开发人员忽略了打扰释放他的资源。出于某种原因,内存中的ActiveXObject阻止或搞砸了对 java.awt.Desktop 类中的默认OS浏览器的Dispatch调用。我认为这是有道理的。

The developer that wrote this code using this ActiveXObject neglected to bother releasing his resources at all. For some reason, this ActiveXObject in memory was preventing or screwing with the Dispatch call to the default OS browser in java.awt.Desktop class. I suppose this makes sense.

我通过声明一个JACOB事务并通过释放finally块中的所有资源来解决这个问题:

I fixed this by declaring a JACOB transaction, and by releasing all resources in a finally block like so:

ActiveXObject ao1 = null;
ActiveXObject ao2 = null;
ComThread.initMTA();
try {
  ao1 = new ActiveXObject("blaa.blaa");
  ao2 = new ActiveXObject("haa.haa");
  // business logic
} finally {
  if (ao1 != null) {
    ao1.safeRelease();
    ao1 = null;
  }
  if (ao2 != null) {
    ao2.safeRelease();
    ao2 = null;
  }
  ComThread.Release();
}

这篇关于Java Desktop.browse偶尔会返回“在任何活动的激活上下文中找不到请求的查找密钥”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆