Jframe程序在运行时给出NoClassDefFoundError

时间:2013-06-07 11:36:40

标签: java exception jframe jlabel

我的代码

import java.awt.*; 
 import javax.swing.*; 

 // Create a simple GUI window
 public class TopLevelWindow {

    private static void createWindow() {

       //Create and set up the window. 
       JFrame frame = new JFrame("Simple GUI");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

       JLabel textLabel = new JLabel("I'm a label in the window",SwingConstants.CENTER); 
       textLabel.setPreferredSize(new Dimension(300, 100)); 
       frame.getContentPane().add(textLabel, BorderLayout.CENTER); 

       //Display the window. 
       frame.setLocationRelativeTo(null); 
       frame.pack();
       frame.setVisible(true); 
    }

    public static void main(String[] args) {

       createWindow();

    }
 } 

我如何运行程序,例外情况是 enter image description here

1 个答案:

答案 0 :(得分:4)

使用.

时,使用/而不是java来指定完全限定的类名
java java1.TopLevelWindow 

还要添加包声明:

package java1;