for(i=1;i<=buylist.size();i++)
/////for(i=0;i<buylist.size();i++)

解决方案 »

  1.   

    该问题已解决,但又出现新的问题!
    我自己创建了一个实例并加到向量中去了!
    indent buy=new indent();
    buy.setId("2");
    buy.setbook("2");
    buy.setauthor("2");
    buy.setprice(2);
    buy.setnum(2);
    buylist.addElement(buylist);
    if(!buylist.isEmpty()){
       for(i=0;i<buylist.size();i++)
       {
        indent current=new indent();
        current=(indent)buylist.elementAt(i);//错误行
        String id=current.getId();
        String book=current.getbook();
        String author=current.getauthor();
        String price=Float.toString(current.getprice());
        toolBar.add(new Label(id));
        toolBar.add(new Label(book));
        toolBar.add(new Label(author));
        toolBar.add(new Label(price));
       
       }
    }
    错误指向行current=(indent)buylist.elementAt(i);错误代码如下:java.lang.ClassCastException
    at bookclass.shopcar.init(shopcar.java:74)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    我知道是类的匹配问题,但我看不出怎么就不匹配了!indent类的结构如下:
    public class indent {
    private String Id;     //ID序列号
    private String book; //书名
    private String author;      //作者
    private float price; //金额
        private int num;
        
    public indent() {
    Id = "";
    book="";
    author="";
    price=0;
    num=0;
    }
    public String getId() {
    return Id;
    } public void setId(String newId){
    this.Id = newId;
    } public String getbook() {
    return book;
    } public void setbook(String newbook) {
    this.book = newbook;
    } public String getauthor() {
    return author;
    } public void setauthor(String newauthor){
    this.author = newauthor;
    } public float getprice() {
    return price;
    } public void setprice(float newprice) {
    this.price = newprice;
    } public int getnum() {
    return num;
    } public void setnum(int newnum) {
    this.num = newnum;
    }
    }
    还请高手指教