为什么我收到此错误:java.lang.Exception:XMLEncoder:丢弃语句Vector.add()?

发布于 2024-09-05 14:06:43 字数 3722 浏览 5 评论 0原文

我的Java程序如下所示:

  public class Biz_Manager
  {
    static Contact_Info_Setting Customer_Contact_Info_Panel;
    static XMLEncoder XML_Encoder;
    ......

    void Get_Customer_Agent_Shipping_Company_And_Shipping_Agent_Net_Worth_Info()
    {
      try
      {
        XML_Encoder=new XMLEncoder(new BufferedOutputStream(new FileOutputStream(Customer_Contact_Info_Panel.Contact_Info_File_Path)));
        XML_Encoder.writeObject(Customer_Contact_Info_Panel.Contacts_Vector);
      }
      catch (Exception e) { e.printStackTrace(); }
      finally
      {
        if (XML_Encoder!=null)
        {
          XML_Encoder.close();   // <== Error here , line : 9459
          XML_Encoder=null;
        }
      }
    }
  }

// =========================================== ==============================

public class Contact_Info_Setting extends JPanel implements ActionListener,KeyListener,ItemListener
{
  public static final long serialVersionUID=26362862L;
  ......
  Vector<Contact_Info_Entry> Contacts_Vector=new Vector<Contact_Info_Entry>();
  ......
}

// ================== =================================================== ===

package Utility;

import java.io.*;
import java.util.*;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Contact_Info_Entry implements Serializable
{
  @PrimaryKey
  @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
  public Long Id;
  public static final long serialVersionUID=26362862L;
  public String Contact_Id="",First_Name="",Last_Name="",Company_Name="",Branch_Name="",Address_1="",Address_2="",City="",State="",Zip="",Country="";
  ......
  public boolean B_1;
  public Vector<String> A_Vector=new Vector<String>();

  public Contact_Info_Entry() { }
  public Contact_Info_Entry(String Other_Id) { this.Other_Id=Other_Id; }
  ......
  public void setId(Long value) { Id=value; }
  public Long getId() { return Id; }

  public void setContact_Id(String value) { Contact_Id=value; }
  public String getContact_Id() { return Contact_Id; }

  public void setFirst_Name(String value) { First_Name=value; }
  public String getFirst_Name() { return First_Name; }

  public void setLast_Name(String value) { Last_Name=value; }
  public String getLast_Name() { return Last_Name; }

  public void setCompany_Name(String value) { Company_Name=value; }
  public String getCompany_Name() { return Company_Name; }
  ......
}

我收到此错误消息:

java.lang.Exception:XMLEncoder:丢弃语句Vector.add(Contact_Info_Entry); 继续... java.lang.Exception: XMLEncoder: 丢弃语句 Vector.add(Contact_Info_Entry); 继续... java.lang.Exception: XMLEncoder: 丢弃语句 Vector.add(Contact_Info_Entry); 继续... java.lang.Exception: XMLEncoder: 丢弃语句 Vector.add(Contact_Info_Entry); 继续... 线程“Thread-8”中的异常 java.lang.NullPointerException 在 java.beans.XMLEncoder.outputStatement(XMLEncoder.java:611) 在 java.beans.XMLEncoder.outputValue(XMLEncoder.java:552) 在 java.beans.XMLEncoder.outputStatement(XMLEncoder.java:682) 在 java.beans.XMLEncoder.outputStatement(XMLEncoder.java:687) 在 java.beans.XMLEncoder.outputValue(XMLEncoder.java:552) 在 java.beans.XMLEncoder.flush(XMLEncoder.java:398) 在 java.beans.XMLEncoder.close(XMLEncoder.java:429) 在 Biz_Manager.Get_Customer_Agent_Shipping_Company_And_Shipping_Agent_Net_Worth_Info(Biz_Manager.java:9459)

似乎无法处理矢量,为什么?有什么问题吗?如何修复它?

坦率

My Java program look like this :

  public class Biz_Manager
  {
    static Contact_Info_Setting Customer_Contact_Info_Panel;
    static XMLEncoder XML_Encoder;
    ......

    void Get_Customer_Agent_Shipping_Company_And_Shipping_Agent_Net_Worth_Info()
    {
      try
      {
        XML_Encoder=new XMLEncoder(new BufferedOutputStream(new FileOutputStream(Customer_Contact_Info_Panel.Contact_Info_File_Path)));
        XML_Encoder.writeObject(Customer_Contact_Info_Panel.Contacts_Vector);
      }
      catch (Exception e) { e.printStackTrace(); }
      finally
      {
        if (XML_Encoder!=null)
        {
          XML_Encoder.close();   // <== Error here , line : 9459
          XML_Encoder=null;
        }
      }
    }
  }

// =======================================================================

public class Contact_Info_Setting extends JPanel implements ActionListener,KeyListener,ItemListener
{
  public static final long serialVersionUID=26362862L;
  ......
  Vector<Contact_Info_Entry> Contacts_Vector=new Vector<Contact_Info_Entry>();
  ......
}

// =======================================================================

package Utility;

import java.io.*;
import java.util.*;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Contact_Info_Entry implements Serializable
{
  @PrimaryKey
  @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
  public Long Id;
  public static final long serialVersionUID=26362862L;
  public String Contact_Id="",First_Name="",Last_Name="",Company_Name="",Branch_Name="",Address_1="",Address_2="",City="",State="",Zip="",Country="";
  ......
  public boolean B_1;
  public Vector<String> A_Vector=new Vector<String>();

  public Contact_Info_Entry() { }
  public Contact_Info_Entry(String Other_Id) { this.Other_Id=Other_Id; }
  ......
  public void setId(Long value) { Id=value; }
  public Long getId() { return Id; }

  public void setContact_Id(String value) { Contact_Id=value; }
  public String getContact_Id() { return Contact_Id; }

  public void setFirst_Name(String value) { First_Name=value; }
  public String getFirst_Name() { return First_Name; }

  public void setLast_Name(String value) { Last_Name=value; }
  public String getLast_Name() { return Last_Name; }

  public void setCompany_Name(String value) { Company_Name=value; }
  public String getCompany_Name() { return Company_Name; }
  ......
}

I got this error message :

java.lang.Exception: XMLEncoder: discarding statement Vector.add(Contact_Info_Entry);
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement Vector.add(Contact_Info_Entry);
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement Vector.add(Contact_Info_Entry);
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement Vector.add(Contact_Info_Entry);
Continuing ...
Exception in thread "Thread-8" java.lang.NullPointerException
at java.beans.XMLEncoder.outputStatement(XMLEncoder.java:611)
at java.beans.XMLEncoder.outputValue(XMLEncoder.java:552)
at java.beans.XMLEncoder.outputStatement(XMLEncoder.java:682)
at java.beans.XMLEncoder.outputStatement(XMLEncoder.java:687)
at java.beans.XMLEncoder.outputValue(XMLEncoder.java:552)
at java.beans.XMLEncoder.flush(XMLEncoder.java:398)
at java.beans.XMLEncoder.close(XMLEncoder.java:429)
at Biz_Manager.Get_Customer_Agent_Shipping_Company_And_Shipping_Agent_Net_Worth_Info(Biz_Manager.java:9459)

Seems it can't deal with vector, why ? Anything wrong ? How to fix it ?

Frank

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼睛会笑 2024-09-12 14:06:43

对我来说这意味着“你需要一个无参数的构造函数”(显然是不同的类)

for me this meant "you need a no arg constructor" (different class, obviously)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文