XMLDecoder java.lang.ClassNotFoundException

时间:2016-04-26 16:40:49

标签: java xml

我在解码之前编码的.xml文件时遇到了一些错误。

所以我有2个类EmailList和Email。

    public class EmailList {

private ArrayList<Email> emails;

public EmailList(){
    this.emails=new ArrayList<Email>();
}

public ArrayList<Email> getEmails() {
    return emails;
}

public void setEmails(ArrayList<Email> emails) {
    this.emails = emails;
}

}


public class Email {

public int emailNumber;
public String sender;
public String reciver;
public String date;
public String subject;
public String content;

public Email(){}

public int getEmailNumber() {
    return emailNumber;
}
public void setEmailNumber(int emailNumber) {
    this.emailNumber = emailNumber;
}
public String getSender() {
    return sender;
}
public void setSender(String sender) {
    this.sender = sender;
}
public String getReciver() {
    return reciver;
}
public void setReciver(String reciver) {
    this.reciver = reciver;
}
public String getDate() {
    return date;
}
public void setDate(String date) {
    this.date = date;
}
public String getSubject() {
    return subject;
}
public void setSubject(String subject) {
    this.subject = subject;
}
public String getContent() {
    return content;
}
public void setContent(String content) {
    this.content = content;
}

}

这是解码器类:

    public class XMLDeserialize {

private static ArrayList<Email> emails=new ArrayList<Email>();
public static EmailList list=new EmailList();

public static void main(String[] args){

    try {
        XMLDecoder x = new XMLDecoder(new BufferedInputStream(new FileInputStream("emails.xml")));
        //System.out.println(x.readObject().toString());
        list=(EmailList)x.readObject();
        //x.close();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }

}   
}

现在当我运行这个时,我得到了这个错误:

   java.lang.ClassNotFoundException: EmailList Continuing ...
   java.lang.ClassNotFoundException: Email Continuing ...
   java.lang.NoSuchMethodException: <unbound>=ArrayList.add();
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   java.lang.IllegalStateException: The outer element does not return value
   Continuing ...
   Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at java.beans.XMLDecoder.readObject(Unknown Source)
       at XMLDeserialize.XMLDeserialize.main(XMLDeserialize.java:20)

我不知道我做错了什么。你能帮助我吗 ? 编辑:这是.xml文件http://www.filedropper.com/emails

0 个答案:

没有答案