我正在尝试创建一种从哈希表中检索用户输入的 articleName 的 authorID 的方法。以下是用户按下按钮时在客户端激活的代码:
public String getAuthorID() // returns a String
{
try
{
articleName = txtArticleName.getText();
argAuthorID = new Vector();// create vector for the args
argAuthorID.addElement(articleName);// name to search for to get AuthorID
// make the call to the server
authorIDVector = (Integer)client.execute("GetSize.sendAuthorID", argAuthorID);
System.out.println(argAuthorID);
}
catch (XmlRpcException exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" +
Integer.toString(exception.code) + ": " +
exception.getCause() + "" + exception.toString());
} catch (Exception exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" + exception.toString());
}
String StrAuthorID = Integer.toString(authorID); // Cast AuthorID to String
return StrAuthorID;
}
这是服务器端的方法:
public int sendAuthorID(String articleNameRequest) {
// get info from the hashtable
aNumber = (Integer) theHashtable.getAuthorID(articleNameRequest); // was this.
return aNumber;
}
这是包含哈希表的类中的代码:
public int getAuthorID(String articleName)
{
int intfoundit;
String foundit = (String)hashtab.get(articleName);
System.out.print(foundit);
intfoundit = Integer.parseInt(foundit);
System.out.print(foundit);
System.out.print(intfoundit);
return intfoundit;
}
程序可以检索 AuthorID,但不会将其输入到文本框中。通过测试我发现异常是由这段代码引发的:
catch (XmlRpcException exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" +
Integer.toString(exception.code) + ": " +
exception.getCause() + "" + exception.toString());
这是给出的错误:
'JavaClient:XML-RPC Consumer Fault #0:nullorg.apache.xmlrpc.XmlRpcException:java.lang.Exception:java.lang.NumberFormatException:对于输入字符串:“3377”'
更新:删除了哈希表中 ID 号之前的空格,它不再抛出错误,但它仍然没有将 ID 号输入到文本框中,而只是输入了一个“0”