当前位置: 代码迷 >> J2SE >> NoClassDefFoundError异常
  详细解决方案

NoClassDefFoundError异常

热度:193   发布时间:2016-04-24 15:49:19.0
NoClassDefFoundError错误
//在解释运行程序时发生了一个奇怪的错误----//                                                                           NoClassDefFoundError
//                                                                         请专家们帮我看看  
/**
        MyColorSliderTest.java
        @author   GeHaiming
        @version   2007-04-30
*/

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

public   class   MyColorSliderTest
{
public   static   void   main(String[]   args)
{
MyColorSliderFrame   frame=new   MyColorSliderFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

/**
      MyColorSliderFrame
*/
class   MyColorSliderFrame   extends   JFrame
{
public   MyColorSliderFrame()
{
setTitle( "My   Color   Slider   Test ");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

//初始化暂存颜色的变量
red=green=blue=256/2;

//sliderPanel
sliderPanel=new   JPanel();
sliderPanel.setLayout(new   GridLayout(3,1));

//事件监听器
listener=new   ChangeListener()
{
public   void   stateChanged(ChangeEvent   event)
{
JSlider   slider=(JSlider)event.getSource();
int   value=slider.getValue();

//这种算法,我并不是很认同,但又找不到时别的方法了
if(value!=red)
{
red=value;
demoPanel.setBackground(new   Color(value,green,blue));
}
else
{
if(value!=green)
{
green=value;
demoPanel.setBackground(new   Color(red,value,blue));
}
else
{
blue=value;
demoPanel.setBackground(new   Color(red,green,value));
}
}
}
};

//redSlider
JSlider   redSlider=new   JSlider(0,256,1);
addSlider(redSlider, "red ");

//greenSlider
JSlider   greenSlider=new   JSlider(0,256,1);
addSlider(greenSlider, "green ");

//blueSlider
JSlider   blueSlider=new   JSlider(0,256,1);
addSlider(blueSlider, "blue ");
}

//添加Slider
public   void   addSlider(JSlider   s,String   description)
{
s.addChangeListener(listener);
JPanel   panel=new   JPanel();
panel.add(s);
panel.add(new   JLabel(description));
sliderPanel.add(panel);
}

private   JPanel   demoPanel;
private   JPanel   sliderPanel;
private   ChangeListener   listener;
private   int   red,green,blue;

public   static   final   int   DEFAULT_WIDTH=400;
public   static   final   int   DEFAULT_HEIGHT=400;

}


------解决方案--------------------
你是不没编译啊,因为错误信息是NoClassDefFoundError,解释器找不到类,只有编译以后才能产生class文件,我帮你编译并运行了一下完全可以,不过只显示出一个窗口.上面什么都没有,呵呵
  相关解决方案