当我只有一台PC时,DVI输出和监视器是VGA输入(所以我使用了一个小的DVi到VGA转换器,我的操作系统是显示器)

Linux显示查询显示以下内容:

$ export DISPLAY=:0.0 && xrandr
xrandr: Failed to get size of gamma for output default
Screen 0: minimum 640 x 480, current 1280 x 1024, maximum 1280 x 1024
default connected 1280x1024+0+0 0mm x 0mm
   1280x1024       0.0*
   1024x768        0.0
   800x600         0.0
   640x480         0.0
  legend (0x10c)   74.5MHz
        h: width  1280 start 1344 end 1472 total 1664 skew    0 clock   44.8KHz
        v: height  720 start  723 end  728 total  748           clock   59.9Hz

-我的Java应用程序在启动时感到困惑,并且无法启动该应用程序,但异常来自dm.getWidth();:
screen = Toolkit.getDefaultToolkit().getScreenSize();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices = ge.getScreenDevices();
for (int i = 0; i < screenDevices.length; i++) {
  System.out.println(screenDevices[i].getIDstring());
  DisplayMode dm = screenDevices[i].getDisplayMode();
  int screenWidth = dm.getWidth();    // this fails....
  int screenHeight = dm.getHeight();
  System.out.println("[myResolution]: " + screenWidth + " " + screenHeight);
  screen.width = screenWidth;
  screen.height = screenHeight;
}

-输出:
[meJavaDebug]: YES i am running

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at main.YumYumYum.createAndShowGUI(YumYumYum.java:167)
    at main.YumYumYum.access$000(YumYumYum.java:42)
    at main.YumYumYum$1.run(YumYumYum.java:118)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
    at java.awt.EventQueue.access$000(EventQueue.java:96)
    at java.awt.EventQueue$1.run(EventQueue.java:608)
    at java.awt.EventQueue$1.run(EventQueue.java:606)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:617)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

Total Garbage Collections: 0
Total Garbage Collection Time (ms): 0

任何想法?

最佳答案

看来screenDevices[i].getDisplayMode()正在您的系统上返回null

它可能与Java Bug数据库中的this bug有关,对于它似乎没有可行的解决方法...除了测试以查看显示模式是否为null且不使用显示模式之外,似乎不可行。

10-06 13:35