2011-04-27 77 views
0

我目前正在嘗試使用常規Ksoap實現從我的webservice檢索數組。但是,試圖訪問該數組時,我收到以下錯誤logcat中:kSoap2 Android - Cast Class Exception(SoapObject)

04-27 00:27:01.772: ERROR/AndroidRuntime(530): Caused by: java.lang.RuntimeException: Unable to 
start activity ComponentInfo{android.waiter/android.waiter.TablesActivity}: 
java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 

看來,由於某種原因,肥皂沒有與我鑄造我的屬性值的方式相處。附件是問題的代碼(和相關方法)

public static TableDTO[] RetrieveFromSoap(SoapObject soap) 
{ 
    TableDTO[] tables = new TableDTO[soap.getPropertyCount()]; 
    for (int i = 0; i < tables.length-1; i++) { 
     SoapObject pii = (SoapObject) soap.getProperty(i); 
     TableDTO table = new TableDTO(); 
     table.setTableID(Integer.parseInt(pii.getProperty(0).toString())); 
     table.setCapacity(Integer.parseInt(pii.getProperty(1).toString())); 
     table.setStatusFlag(pii.getProperty(2).toString()); 
     table.setCurrentWaiter(pii.getProperty(3).toString()); 
     tables[i] = table; 
    } 
    return tables; 
} 

TableDTO信息:

@Override 
public Object getProperty(int arg0) { 
    switch(arg0) 
    { 
    case 0: 
     return TableID; 
    case 1: 
     return Capacity; 
    case 2: 
     return StatusFlag; 
    case 3: 
     return currentWaiter; 
    } 
    return null; 
} 

@Override 
public int getPropertyCount() { 
    // TODO Auto-generated method stub 
    return 3; 
} 

@Override 
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo info) { 
    switch(arg0){ 
    case 0: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "TableID"; 
     break; 
    case 1: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "Capacity"; 
     break; 
    case 2: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "StatusFlag"; 
     break; 
    case 3: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "currentWaiter"; 
     break; 
default:break; 
    }  

} 

@Override 
public void setProperty(int arg0, Object value) { 
    switch(arg0) 
    { 
    case 0: 
     TableID = Integer.parseInt(value.toString()); 
     break; 
    case 1: 
     Capacity = Integer.parseInt(value.toString()); 
     break; 
    case 2: 
     StatusFlag = value.toString(); 
     break; 
    case 3: 
     currentWaiter = value.toString(); 
     break; 
    default : 
     break; 

    } 

} 

問題是與

SoapObject pii = (SoapObject) soap.getProperty(i); 

它不喜歡鑄造有行。我對如何解決這個問題感到茫然。

感謝您的時間和幫助!

回答

15

而不是使用

SoapObject response = (SoapObject)envelope.getResponse(); 

使用

SoapObject response = (SoapObject)envelope.bodyIn; 

爲我工作的。

+0

偉大的答案,快速,簡單,並解決了我的問題。謝謝您的幫助! – BPuryear 2011-04-27 15:59:13