How to fix “(java:22494): Gdk-WARNING…”

。_饼干妹妹 提交于 2021-01-28 11:10:02

问题


I am writing a javafx program and I need the panel to update at a constant rate. Right now it is set to update every second. But I got this error, which is usually (but not always) followed by a glitch in the panel when the whole scene becomes distorted (it like mirrors in on itself in a weird choppy x pattern. hard to explain).

Full error: (java:22494): Gdk-WARNING **: 18:38:59.118: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.

This is the code I have for the timer:

Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run()  {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            String x = txtDisplay.getText();
                            txtDisplay.setText(x.substring(1, x.length()) + x.substring(0, 1));
                        } catch (NullPointerException e) {
                            System.out.println("Error.");
                        }
                    }
                });
            }
        }, 0, 500);

I think the issue is with the above block, like maybe I am breaking some fundamental swing rule. My other idea is that it has something with two methods editing the same text area at the same time, because I have other methods setting the text area's text.

I would be happy with either a solution to the error or a better way of executing the above method. Just needs to run every second without crashing.

Thanks.

EDIT: A new developement, I am now consistently getting a "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" but the stacktrace does not reference any locations that are in my code.


回答1:


This looks like is is related to JDK-8156779 (see also JDK-8211305). I.e. there are some issues with JDK 8, 9 and 11 and GTK 3.

For me (on Linux Mint 20.1 and Open JDK 11, Bellsoft 11.0.10.fx-librca) the solution was to force GTK 2 with -Djdk.gtk.version=2

Others have solved it by upgrading to JDK 12 or higher.



来源:https://stackoverflow.com/questions/55446534/how-to-fix-java22494-gdk-warning

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