QQ1252776430 2016-03-14 05:54 采纳率: 22%
浏览 2074

javabean报错java.lang.ClassNotFoundException

如题,只是书上的简单例子,三个类放在一个包中,用IntrospectorDemo去解析Colors类,系统提示java.lang.ClassNotFoundException。不知道哪边有问题。

import java.beans.*;

public class IntrospectorDemo
{
public static void main(String[] args)
{
try{Class<?> c=Class.forName("Colors");
BeanInfo beanInfo=Introspector.getBeanInfo(c);
System.out.println("Properties:");
PropertyDescriptor propertyDescriptor[]=beanInfo.getPropertyDescriptors();
for(int i=0;i<propertyDescriptor.length;i++)
{System.out.println(propertyDescriptor[i].getName());}

System.out.println("Events:");
EventSetDescriptor eventSetDescriptor[]=beanInfo.getEventSetDescriptors();
for(int i=0;i<eventSetDescriptor.length;i++)
{System.out.println(eventSetDescriptor[i].getName());}
}catch(Exception e)
{System.out.println(e);}

}

}

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;

public class ColorsBeanInfo extends SimpleBeanInfo {

public PropertyDescriptor[] getPropertyDescriptors()
{
    try{PropertyDescriptor rectangular=new PropertyDescriptor("rectangular",Colors.class);
    PropertyDescriptor pd[]={rectangular};
    return pd;
    }
    catch(Exception e)
    {System.out.println(e);}
    return null;
}

}

public class Colors extends Canvas implements Serializable{

transient private Color color;
private boolean rectangular=false;

public Colors()
{
addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent me){change();}
});

setSize(200,100);
change();
}

public boolean getRectangular()
{return rectangular;}

public void setRectangular(boolean flag)
{this.rectangular=flag;
repaint();}

public void change()
{color=randomColor();
repaint();}

private Color randomColor()
{int r=(int)(255*Math.random());
int g=(int)(255*Math.random());
int b=(int)(255*Math.random());
return new Color(r,g,b);
}

public void paint(Graphics g)
{
Dimension d=getSize();
int h=d.height;
int w=d.width;
g.setColor(color);
if(rectangular){g.fillRect(0, 0, w-1, h-1);}
else
{g.fillOval(0, 0, w-1, h-1);}

}

}

  • 写回答

3条回答

  • 把分全给哥 2016-03-14 06:10
    关注

    没有找到要加载的类,查看是否正确引用包

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题