Java getDefaultToolKit() hangs Mac OS X 10.5

旧时模样 提交于 2019-12-11 15:58:46

问题


I am using Eclipse Cocao on Mac OS X 10.5.7, and the program hangs on the innocent line below while initializing variables. If I take it out, the program proceeds.

Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

This line works fine in XP, Vista, Server 2003, and Mac OS X 10.4.11. I have no idea why it infinitely hangs now in 10.5. Any ideas?

Update: This appears to me to be a bug when using Cocoa Eclipse and Cocoa SWT. I can reproduce the example from Thorbjørn below without any problem. When I run the test program here though, I get the hanging behavior.

import java.awt.Dimension;
import org.eclipse.swt.widgets.Display;

public class Foo {
  static Display display = new Display();

  public Foo() {
    Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    System.out.println(screenSize);
  }

  public static void main(String[] args) {
    Foo test = new Foo();
  }
} 

回答1:


The following code completes with Eclipse Cocoa 3.5 under OS X 10.5 on a MacBook with both Java 1.5 and Java 6.

package main;

import java.awt.Dimension;

public class Foo {

    public static void main(String[] args) {
        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
                .getScreenSize();
        System.out.println(screenSize);
    }
}

You will have to provide more details about how your system is different from mine.




回答2:


Launch your application with the -Djava.awt.headless=true JVM argument.



来源:https://stackoverflow.com/questions/1201085/java-getdefaulttoolkit-hangs-mac-os-x-10-5

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