开发者

Java Desktop.browse occasionally returning "requested lookup key not found in any active activation context"

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

Desktop.bro开发者_高级运维wse("some url");

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.

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

EDIT: 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: 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"); was throwing this error because in a previous step in the application an ActiveXObject was opened programmatically using the JACOB framework.

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.

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜