我想創建一個從散列表中檢索用戶輸入的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消費故障#0: nullorg.apache。 xmlrpc.XmlRpcException:java.lang.Exception的: java.lang.NumberFormatException:對於輸入字符串:「3377」」
UPDATE:除去在哈希表的ID號之前的空間和它不會引發錯誤anym礦石,但它仍然沒有輸入到文本框中的ID號碼,而只是輸入'0'
我只是這樣做,它解決了問題,但該方法似乎並沒有實際返回身份證號碼出於某種原因 –