JViewport.setView 无法捕捉的错误 [英] uncatchable error with JViewport.setView

查看:29
本文介绍了JViewport.setView 无法捕捉的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能提供 SSCCE,因为我不能在我的大型应用程序之外重复错误.

I CANNOT provide an SSCCE as I can't make error repeatable outside of my large App.

但这是一个片段和输出:

But here is a snippet and the output:

            if (vp != null) {
                try {
                    starterModule.writePaneln("Sigma.show() 4.1 vp: "+vp);
                    starterModule.writePaneln("Sigma.show() 4.1 P: "+P);
                    starterModule.writePaneln("Sigma.show() 4.1 scrollPane: "+scrollPane);

                    vp.setView(P);
                    starterModule.writePaneln("Sigma.show() 4.2");

                } catch (Exception e) {
                    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\javaout2.txt", true)));
                    out.println("ERROR SIGMA e:");
                    out.flush();
                    out.close();
                }
            }

输出为:

    Sigma.show() 4.1 vp: javax.swing.JViewport[,0,0,902x800,layout=javax.swing.ViewportLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=25165832,maximumSize=,minimumSize=,preferredSize=,isViewSizeSet=true,lastPaintPosition=,scrollUnderway=false]
    Sigma.show() 4.1 P: javax.swing.JPanel[,0,0,0x0,invalid,layout=javax.swing.BoxLayout,alignmentX=0.0,alignmentY=0.0,border=com.devexperts.dxpro.shared.swing.styles.support.border.DefaultBorderSetter$PaddingBorder@4719dad8,flags=9,maximumSize=,minimumSize=,preferredSize=]
    Sigma.show() 4.1 scrollPane: javax.swing.JScrollPane[,0,30,917x800,layout=javax.swing.ScrollPaneLayout$UIResource,alignmentX=0.0,alignmentY=0.0,border=com.devexperts.dxpro.shared.swing.styles.support.border.DefaultBorderSetter$PaddingBorder@14716d46,flags=328,maximumSize=,minimumSize=,preferredSize=,columnHeader=,horizontalScrollBar=javax.swing.JScrollPane$ScrollBar[,0,0,0x0,hidden,layout=com.devexperts.dxpro.shared.swing.styles.laf.impl.basic.StyledScrollBarUI,alignmentX=0.0,alignmentY=0.0,border=,flags=4194632,maximumSize=,minimumSize=,preferredSize=,blockIncrement=10,orientation=HORIZONTAL,unitIncrement=1],horizontalScrollBarPolicy=HORIZONTAL_SCROLLBAR_AS_NEEDED,lowerLeft=,lowerRight=,rowHeader=,upperLeft=,upperRight=,verticalScrollBar=javax.swing.JScrollPane$ScrollBar[,902,0,15x800,layout=com.devexperts.dxpro.shared.swing.styles.laf.impl.basic.StyledScrollBarUI,alignmentX=0.0,alignmentY=0.0,border=,flags=4194632,maximumSize=,minimumSize=,preferredSize=,blockIncrement=10,orientation=VERTICAL,unitIncrement=1],verticalScrollBarPolicy=VERTICAL_SCROLLBAR_ALWAYS,viewport=javax.swing.JViewport[,0,0,902x800,layout=javax.swing.ViewportLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=25165832,maximumSize=,minimumSize=,preferredSize=,isViewSizeSet=true,lastPaintPosition=,scrollUnderway=false],viewportBorder=]

然后程序似乎在 vp.setView(P) 上冻结;因为不会调用下一个 writePaneln.

Then the program appears to freeze on vp.setView(P); as the next writePaneln is not called.

然而,错误也没有被捕获......

HOWEVER, the error is not trapped either....

这里是 writePaneln(为了完整性)

Here writePaneln ( for completeness)

public static void writePaneln(String txt){
    if(DEBUG){
    try {
        synchronized (textPane) {
            //textPane.getDocument().insertString(textPane.getDocument().getLength(), txt + "\n", null);

            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\javaout.txt", true)));
            out.println(txt);
            out.flush();
            out.close();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        JOptionPane.showMessageDialog(null,"writePaneln ERROR: "+e);
    }   
    }
}

编辑 1

我已改为在我的 java.util.timer 中使用 invokeLater:

I have changed to using invokeLater in my java.util.timer:

        class RemindTask extends TimerTask {

               @Override
               public void run() {
                   SwingUtilities.invokeLater(
                           new Runnable(){

                               @Override
                                public void run() {
                                   handleGO();
                                };
                           }
                   );
               }
       }

推荐答案

如果调用线程既不返回也不抛出异常,显然是卡在了某个地方.您可以尝试两件事:

If the calling thread neither returns nor throws an exception, it is obviously stuck somewhere. You can try two things:

  1. 附加一个调试器,看看从 setView 调用开始发生了什么(如@DeltaLima 所建议的)
  2. 运行该东西并创建一个线程转储(说明因操作系统而异,不幸的是您没有提到您的).线程转储将准确显示您的程序卡在何处以及为什么卡住,即哪个其他线程可能持有您想要的锁.
  1. Attach a debugger and see what happened starting from the setView call (as suggested by @DeltaLima)
  2. Run the thing and create a thread dump (instructions differ based on OS, unfortunately you didn't mention yours). The thread dump will show you exactly where your program is stuck and why it is stuck, i.e. what other thread may hold a lock that yours wants.

我建议从 2. 开始,因为它既便宜又快捷.

I'd recommend to start with 2., as it is cheap and quick.

祝你好运.

这篇关于JViewport.setView 无法捕捉的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆