如果需要在不使用java.util.map的情况下创建可序列化的键值映射,请使用我的解决方法继续运行到NullPointerException
我正在尝试使用OracleAS web服务使用第三方web服务。我试图调用的操作请求一个java.util.Map作为其输入参数之一。它期待着这样的结构:如果需要在不使用java.util.map的情况下创建可序列化的键值映射,请使用我的解决方法继续运行到NullPointerException,java,serialization,Java,Serialization,我正在尝试使用OracleAS web服务使用第三方web服务。我试图调用的操作请求一个java.util.Map作为其输入参数之一。它期待着这样的结构: <in1> <!--Zero or more repetitions:--> <item> <key>?</key> <value>?</value> </item> </in1>
<in1>
<!--Zero or more repetitions:-->
<item>
<key>?</key>
<value>?</value>
</item>
</in1>
CustomItem类
public class CreateStructure {
public static void main(String[] args) {
CustomItem inputParamMap = new CustomItem(2);
inputParamMap.setItem("HireDate", "2011-12-31", 0);
inputParamMap.setItem("status", "Hired", 1);
}
}
public class CustomItem implements java.io.Serializable {
protected JAXRpcMapEntry[] item;
//Constructor
public CustomItem(int index) {
item = new JAXRpcMapEntry[index];
}
//methods
public JAXRpcMapEntry[] getItem() {
return item;
}
public void setItem(JAXRpcMapEntry[] item) {
this.item = item;
}
public void setItem(java.lang.Object key, java.lang.Object value, int index) {
this.item[index].setKey((String)key);
this.item[index].setValue((String)value);
}
public JAXRpcMapEntry[] getItem(int index) {
return this.getItem(index);
}
}
public class JAXRpcMapEntry
implements java.io.Serializable
{
//
// Constructors
//
public JAXRpcMapEntry() { }
public JAXRpcMapEntry(java.lang.Object p1, java.lang.Object p2) { }
//
// Fields
//
private java.lang.Object key;
private java.lang.Object value;
//
// Methods
//
public java.lang.Object getKey() {
return this.key;
}
public void setKey(java.lang.Object p1) { }
public java.lang.Object getValue() {
return this.value;
}
public void setValue(java.lang.Object p1) { }
public boolean equals(java.lang.Object p1) {
if(this.equals(p1)){
return true;
}
else
{
return false;
}
}
}
jaxrpcmpentry类
public class CreateStructure {
public static void main(String[] args) {
CustomItem inputParamMap = new CustomItem(2);
inputParamMap.setItem("HireDate", "2011-12-31", 0);
inputParamMap.setItem("status", "Hired", 1);
}
}
public class CustomItem implements java.io.Serializable {
protected JAXRpcMapEntry[] item;
//Constructor
public CustomItem(int index) {
item = new JAXRpcMapEntry[index];
}
//methods
public JAXRpcMapEntry[] getItem() {
return item;
}
public void setItem(JAXRpcMapEntry[] item) {
this.item = item;
}
public void setItem(java.lang.Object key, java.lang.Object value, int index) {
this.item[index].setKey((String)key);
this.item[index].setValue((String)value);
}
public JAXRpcMapEntry[] getItem(int index) {
return this.getItem(index);
}
}
public class JAXRpcMapEntry
implements java.io.Serializable
{
//
// Constructors
//
public JAXRpcMapEntry() { }
public JAXRpcMapEntry(java.lang.Object p1, java.lang.Object p2) { }
//
// Fields
//
private java.lang.Object key;
private java.lang.Object value;
//
// Methods
//
public java.lang.Object getKey() {
return this.key;
}
public void setKey(java.lang.Object p1) { }
public java.lang.Object getValue() {
return this.value;
}
public void setValue(java.lang.Object p1) { }
public boolean equals(java.lang.Object p1) {
if(this.equals(p1)){
return true;
}
else
{
return false;
}
}
}
获取空指针异常的原因是数组中的元素未初始化。换句话说,您正在将key和value设置为null对象。快速解决办法是:
public void setItem(java.lang.Object key, java.lang.Object value, int index) {
this.item[index] = new JAXRpcMapEntry(key, value);
}
你是我周五下午的英雄!非常好,谢谢你的帮助。