这里TP_DSCVoyChange类有KEY_DSC
作为我们要填充此KEY_DSC
的属性
使用TP_DSCVoyChange
构造函数使用String值从Java获取的值。例如。 voyagelist.addElement(new TP_DSCVoyChange(dscDetails.strDscKey,dscDetails.voyage));
但是发生错误dscDetails.strDscKey
是字符串而不是KEY_DSC
类型。
你能告诉我如何解决它吗?
public final class TP_DSCVoyChange implements IDLEntity
{
public KEY_DSC key;
public String voyNumbers[];
private transient Hashtable _printMap;
private transient Hashtable _cmpMap;
public TP_DSCVoyChange()
{
_printMap = null;
_cmpMap = null;
}
public TP_DSCVoyChange(KEY_DSC key_dsc, String as[])
{
_printMap = null;
_cmpMap = null;
key = key_dsc;
voyNumbers = as;
}
public String toString()
{
StringBuffer stringbuffer = new StringBuffer("struct idl.TP_DSCVoyChange {");
Thread thread = Thread.currentThread();
boolean flag = false;
if(_printMap == null)
{
synchronized(this)
{
if(_printMap == null)
{
flag = true;
_printMap = new Hashtable();
}
}
}
if(!flag && _printMap.get(thread) != null)
{
stringbuffer.append("...}");
return stringbuffer.toString();
}
_printMap.put(thread, this);
stringbuffer.append("\n");
stringbuffer.append("idl.KEY_DSC key=");
stringbuffer.append(key);
stringbuffer.append(",\n");
stringbuffer.append("java.lang.String[] voyNumbers=");
stringbuffer.append("{");
if(voyNumbers == null)
{
stringbuffer.append(voyNumbers);
} else
{
for(int i = 0; i < voyNumbers.length; i++)
{
stringbuffer.append(voyNumbers[i] == null ? null : (new StringBuilder()).append('"').append(voyNumbers[i]).append('"').toString());
if(i < voyNumbers.length - 1)
{
stringbuffer.append(",");
}
}
}
stringbuffer.append("}");
stringbuffer.append("\n");
_printMap.remove(thread);
stringbuffer.append("}");
return stringbuffer.toString();
}
public boolean equals(Object obj)
{
if(this == obj)
{
return true;
}
if(obj == null)
{
return false;
}
Thread thread = Thread.currentThread();
boolean flag = false;
if(_cmpMap == null)
{
synchronized(this)
{
if(_cmpMap == null)
{
flag = true;
_cmpMap = new Hashtable();
}
}
}
if(!flag)
{
Object obj1 = _cmpMap.get(thread);
if(obj1 != null)
{
return obj == obj1;
}
}
if(obj instanceof TP_DSCVoyChange)
{
_cmpMap.put(thread, obj);
TP_DSCVoyChange tp_dscvoychange1 = (TP_DSCVoyChange)obj;
boolean flag1 = true;
flag1 = key == tp_dscvoychange1.key || key != null && tp_dscvoychange1.key != null && key.equals(tp_dscvoychange1.key);
if(flag1 && (flag1 = voyNumbers.length == tp_dscvoychange1.voyNumbers.length))
{
for(int i = 0; flag1 && i < voyNumbers.length; i++)
{
flag1 = voyNumbers[i] == tp_dscvoychange1.voyNumbers[i] || voyNumbers[i] != null && tp_dscvoychange1.voyNumbers[i] != null && voyNumbers[i].equals(tp_dscvoychange1.voyNumbers[i]);
}
}
_cmpMap.remove(thread);
return flag1;
} else
{
return false;
}
}
}
public final class KEY_DSC implements IDLEntity
{
public int dsc;
public KEY_DSC()
{
}
public KEY_DSC(int i)
{
dsc = i;
}
public String toString()
{
StringBuffer stringbuffer = new StringBuffer("struct idl.KEY_DSC {");
stringbuffer.append("\n");
stringbuffer.append("int dsc=");
stringbuffer.append(dsc);
stringbuffer.append("\n");
stringbuffer.append("}");
return stringbuffer.toString();
}
public boolean equals(Object obj)
{
if(this == obj)
{
return true;
}
if(obj == null)
{
return false;
}
if(obj instanceof KEY_DSC)
{
KEY_DSC key_dsc = (KEY_DSC)obj;
boolean flag = true;
flag = dsc == key_dsc.dsc;
return flag;
} else
{
return false;
}
}
}
答案 0 :(得分:1)
这些
public TP_DSCVoyChange() {/* [...] */}
public TP_DSCVoyChange(KEY_DSC key_dsc, String as[]) {/* [...] */}
是你的ctors,但是这个
TP_DSCVoyChange(dscDetails.strDscKey,dscDetails.voyage)
是你如何称呼它。所以你试着提供
dscDetails.strDscKey
这显然是一个字符串,对于一个根本不存在的ctor的第一个形式参数 - “B”的第一个形式参数,即你显然想要使用的ctor,是“KEY_DSC”类型,不是String,也不是它的后代之一。
答案 1 :(得分:0)
Vector voyagelist =new Vector();
int dsc =Integer.parseInt(dscDetails.strDscKey);
KEY_DSC keyDSC = new KEY_DSC(dsc);
System.out.println(keyDSC.toString());
voyagelist.addElement(new TP_DSCVoyChange(keyDSC,dscDetails.voyage));
因为KEY_DSC类有一个构造函数,它接受int参数,然后将string转换为int并将其传递给ctor解决问题。