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);}

}

}

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

解决了,加上包名就可以了,package01.Colors

必须有包名,且不能是缺省包