本文介绍了Java getDefaultToolKit()挂起Mac OS X 10.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS X 10.5.7上使用Eclipse Cocao,并且该程序在初始化变量时挂在下面的无辜行上.如果我将其取出,程序将继续进行.

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.

维度screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

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

此行在XP,Vista,Server 2003和Mac OS X 10.4.11中正常工作.我不知道为什么它现在无限地挂在10.5中.有什么想法吗?

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?

更新:在我看来,当使用Cocoa Eclipse和Cocoa SWT时,这是一个错误.我可以毫无问题地从下面的Thorbjørn复制示例.但是,当我在此处运行测试程序时,出现挂起行为.

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

推荐答案

以下代码在装有Java 1.5和Java 6的MacBook上,在OS X 10.5和Eclipse Cocoa 3.5下完成.

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.

这篇关于Java getDefaultToolKit()挂起Mac OS X 10.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:37