2012-04-19 69 views
0

我试图设置我的GUI的外观和感觉。我已经发现了UnsupportedLookAndFeelException,但是当我编译时,我得到一个错误,说UnsupportedLookAndFeelException必须被捕获或声明为抛出。错误在这条线上:Ne r = new Ne();已被捕获的异常,仍然给出错误

下面的代码:

public static void main(String[] args) { 

    try{ 
     UIManager man = new UIManager(); 
     man.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel") ; 
    } 
    catch(UnsupportedLookAndFeelException ex){} 
    catch(Exception ex){} 

    SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 
     Ne r = new Ne(); 
     r.setVisible(true); 
     } 
    }); 
} 
+0

是你制作的对象类型吗?如果是这样,构造函数是否有'@Throws UnsupportedLookAndFellException'语句?那班怎么样? – 2012-04-19 23:28:27

回答

0

我看不到你的代码将是如何捕获()由新氖抛出的UnsupportedLookAndFeelException。为什么不把试衣服放在正确的水平?即:

public void run() 
{ 
    try 
    { 
     Ne r = new Ne(); 
     r.setVisible(true); 

    } catch (UnsupportedLookAndFeelException e) 
    { 
     // Put some code here to do the right thing. 
    } 
} 
+0

我试过了,仍然给我同样的问题。 – 2012-04-19 20:31:47

3

我建议阅读多一些的尝试catch语句:

http://docs.oracle.com/javase/tutorial/essential/exceptions/

一切的一切,似乎并不是所有的代码,能抛出异常是由包围try.catch块

如果您在Ne r = new Ne()时出错,请将其移入try catch语句。

public static void main(String[] args) { 

    try{ 
     UIManager man = new UIManager(); 
     man.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel") ; 
     SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 
      Ne r = new Ne(); 
      r.setVisible(true); 
     } 
     }); 
    } 
    catch(UnsupportedLookAndFeelException ex){} 
    catch(Exception ex){} 
} 

如果使用IDE,比如Eclipse,它在错误的固定方法的一些建设,将围绕着你需要的代码这是一个良好的开端,以找出需要在try catch块

要设置什么