2010-07-15 52 views
2

我的Eclipse項目中有一個構建文件。此文件所做的其中一件事是使用<input/>標籤通過提示詢問問題。自從升級到Eclipse太陽神,這不再工作,因爲我發現了以下錯誤:Ant <input/>不再在Eclipse Helios中工作(3.6)

[input] ***WARNING: Display must be created on main thread due to Cocoa restrictions.

Invalid thread access

如何解決這個問題?

回答

1

終於找到了這個問題的解決方案:

首先,確保你的Java版本是最新的(在寫這篇文章的時候是1.6.0.20)。

  1. 開放:其次,這樣做改變你的Ant運行參數運行>外部工具>外部工具配置
  2. 選擇構建文件
  3. 打開JRE選項卡
  4. 在VM參數輸入框,請添加以下內容:-XstartOnFirstThread
+0

很高興知道您確實找到了解決方案:) – VonC 2010-08-31 10:23:35

+0

剛剛更新了我的答案,其中提供了一些有關選項「XstartOnFirstThread」的參考和警告 – VonC 2010-08-31 10:30:20

3

它看起來像bug 303869

I've submitted at feature request to Apple: Bug ID# 7840189 .
If we have the possibility to run the display code on the main thread via this new Dispatch object/method, I think that SWT can be made to work in applets without changing too much code, isn't it ?

檢查也bug 288436,看它是否是你的情況相關。

+0

看起來很相關,是的。但是他們沒有提供路徑或解決方法,並且該錯誤還沒有解決(5個月後),所以我仍然沒有解決方案。 – 2010-07-15 07:02:09

2

關於我以前的答案,現在這兩個錯誤都已修復。

特別bug 303869已經在本月初封閉:

I think we can close this bug, it works well now with the latest Java Update for Mac OS X 10.6.
We can execute code on the main thread and now the UI is displayed. In the applet we use code like the following to instantiate the display:

com.apple.concurrent.Dispatch.getInstance().getNonBlockingMainQueueExecutor().execute(
new Runnable(){ 

      @Override 
      public void run() { 

       if(dDisplay == null) 
       { 
        dDisplay = Display.getDefault();  
        sShell = SWT_AWT.new_Shell(dDisplay, cCanvas); 
        mLogger.info("Display is created"); 
       } 
... 
      } 
     }); 
... 

Thanks all and especially Mike from Apple to have solved the problem, it was not so much related to SWT IMHO.


bug 288436

Yes, the JNLP file has a small error that is triggering the problem.
Specifying " <j2se version="1.6*" /> " in the " <resources> " tag without any other attributes is throwing off the JNLP parser and causing the later line " <j2se version="1.6*" java-vm-args="-XstartOnFirstThread"/> " to be ignored.
The two lines end up referring to two separate JVMs, and the first specification is 'winning'. That spec has no VM arguments on it, so the JVM starts normally, and the SWT is loaded on the wrong thread.


選項-XstartOnFirstThreadbug 211625提到:

It's needed because Cocoa has a requirement that all user event dispatch must happen on thread 0.
Without -XstartOnFirstThread , Display will create an NSApplication on a non-main thread, and the SWT won't be able to pull and dispatch events from the non-main thread.

即使被用-XstartOnFirstThread選項小心:liek此bug mentions

The reason for this is that the new Developer Mode is implemented in Swing, and the old Hosted Mode was implemented in SWT.
SWT requires -XstartOnFirstThread to be working on a Mac.
But this however breaks any java program using Swing.

So you cannot add -XstartOnFirstThread from version 2.0 and forward. On the older versions however it is still a requirement.

+0

不幸的是我的Java版本已經是最新的。但我確實找到了解決方案,我在下面發佈。您的答案中的'-XstartOnFirstThread'位設置在正確的軌道上:+1 – 2010-08-31 07:53:19

相關問題