2013-08-17 4 views
1

해시 테이블에서 사용자가 입력하는 articleName에 대한 authorID를 검색하는 방법을 만들려고합니다. 이 포함 된 클래스 코드는텍스트 상자에 인쇄하지 않습니다.

public int sendAuthorID(String articleNameRequest) { 
     // get info from the hashtable 
     aNumber = (Integer) theHashtable.getAuthorID(articleNameRequest); // was this. 
     return aNumber; 
    } 

: 서버 측에서 상기 방법은

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 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를 검색 할 수 있지만 입력란에는 입력하지 않습니다. 테스트를 통해 나는 예외가이 코드에 의해 발생 된 것을 발견 :

'JavaClient : XML-RPC 소비자 오류 # 0 : nullorg.apache

catch (XmlRpcException exception) { 
      System.err.println("JavaClient: XML-RPC Consumer Fault #" + 
      Integer.toString(exception.code) + ": " + 
           exception.getCause() + "" + exception.toString()); 

이 부여되는 오류입니다. xmlrpc.XmlRpcException : java.lang.Exception가 : java.lang.NumberFormatException의 : 입력 문자열 : "3377" '

업데이트 : 해시 테이블에있는 ID 번호 앞에 공간을 제거하고 포기하지 않는 오류 anym 광석을 입력했지만 여전히 입력란에 ID 번호가 입력되지 않고 '0'이 입력됩니다.

답변

1

문자열에 공백이있는 경우 오류가 발생하는 것 같습니다. 우리는 당신의 예외 추적에서 볼 수 있듯이 parseInt" 3377"를 구문 분석하는 데 실패하고 실행하는 동안이 NumberFormatException을 던졌다 :

intfoundit = Integer.parseInt(foundit.trim()); 
: 그것은 당신의 문제를 해결 여부를
intfoundit = Integer.parseInt(foundit); 

그래서 당신이 trim에 문자열을 시도하고 볼 수 있습니다

해시 테이블에 키/값을 저장하거나 넣는 위치를 조정해야합니다.

+0

방금 ​​문제를 해결했지만 방법이 실제로 어떤 이유로 든 ID 번호를 반환하지 않는 것 같습니다. –

0

첫 번째 문제에 대한 해답은 공간을 정수로 변환 할 수 없기 때문에 해시 테이블의 ID 번호 앞에있는 공간이었습니다.

두 번째 문제에 대한 답은 정수가 AuthorID 변수

에 있었기 때문에 다음 줄이 잘못된 변수를

String StrAuthorID = Integer.toString(authorID); // Cast AuthorID to String 

변환하려고했던 내가

 authorIDVector = (Integer)client.execute("GetSize.sendAuthorID", argAuthorID); 
을 변경하여이 수정이었다

to

 authorID = (Integer)client.execute("GetSize.sendAuthorID", argAuthorID); 
관련 문제