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

↘锁芯ラ 提交于 2020-01-25 09:45:13

问题


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

Desktop.browse("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.


回答1:


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


来源:https://stackoverflow.com/questions/6257049/java-desktop-browse-occasionally-returning-requested-lookup-key-not-found-in-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!