2016-08-23 59 views
0

下面是使用Propertyware API的代碼部分。如何解決java.lang.ClassCastException?

public OwnerLedger appendOwnerLedgerItems(OwnerLedger ownerLedger, Owner owner) { 
    object[] results = this.Invoke("appendOwnerLedgerItems", new object[] { 
       ownerLedger, 
       owner}); 
    return ((OwnerLedger)(results[0])); 
} 

public partial class OwnerLedger : Ledger { 
} 

public abstract partial class Ledger : ClientDataContainer { 

private LedgerItem[] itemsField; 

/// <remarks/> 
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)] 
public LedgerItem[] items { 
    get { 
     return this.itemsField; 
    } 
    set { 
     this.itemsField = value; 
    } 
} 
} 

public abstract partial class LedgerItem : FinancialTransaction { 
} 

public abstract partial class OwnerLedgerItem : LedgerItem { 
} 

public partial class OwnerContribution : OwnerLedgerItem { 

private string commentsField; 

private System.Nullable<System.DateTime> dateField; 

private string paymentTypeField; 

private string referenceNumberField; 

/// <remarks/> 
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)] 
public string comments { 
    get { 
     return this.commentsField; 
    } 
    set { 
     this.commentsField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)] 
public System.Nullable<System.DateTime> date { 
    get { 
     return this.dateField; 
    } 
    set { 
     this.dateField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)] 
public string paymentType { 
    get { 
     return this.paymentTypeField; 
    } 
    set { 
     this.paymentTypeField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)] 
public string referenceNumber { 
    get { 
     return this.referenceNumberField; 
    } 
    set { 
     this.referenceNumberField = value; 
    } 
} 
} 

在上面的代碼我需要使用「appendOwnerLedgerItems」方法來創建在Propertyware所有者貢獻項。爲此,我嘗試使用下面的邏輯,但失敗了。錯誤消息是「java.lang.ClassCastException:[Lcom.realpage.propertyware.web.service.soap.AbstractLedgerItemDTO;不能轉換爲[Lcom.realpage.propertyware.web.service.soap.AbstractOwnerLedgerItemDTO;」

OwnerContribution oc = new OwnerContribution(); 
       oc.amount = 10; 
       oc.comments = "Test Entry"; 
       oc.date = System.DateTime.Now; 
       oc.paymentType = "Check"; 
       oc.referenceNumber = "12345"; 


Owner ow = new Owner(); 
     ow.ID = 12345; 

LedgerItem[] li = new LedgerItem[1]; 
      li[0] = oc; 

OwnerLedger owl = new OwnerLedger(); 
      owl.items = li; 

OwnerLedger owl1 = client.appendOwnerLedgerItems(owl,ow); // This is where i get the cast error 

如何解決這個問題?

+0

我想您所提供的對象的一個​​有父AbstractLedgerItemDTO或AbstractOwnerLedgerItemDTO,服務器期望反過來,嘗試通過這個:** new object [] {owner,ownerLedger} ** – tonakai

+0

@tonakai你想讓我通過上面提到的code.Could你請詳細一點更多? – Ean

回答

0

我不知道很多關於Propertyware,但你可以試試這個,基本上改變傳遞給invoke方法對象的順序:

public OwnerLedger appendOwnerLedgerItems(OwnerLedger ownerLedger, Owner owner) { 
    object[] results = this.Invoke("appendOwnerLedgerItems", new object[] { 
       owner, ownerLedger}); 
    return ((OwnerLedger)(results[0])); 
} 
+0

如果我這樣做,然後我得到以下錯誤「無法投入類型'Pin.com.propertyware.Owner'的對象鍵入'Pin.com.propertyware.OwnerLedger' – Ean

+0

是否正確修改Web服務引用代碼,因爲您在上面建議的是Propertyware API參考中的代碼。 – Ean

+0

是的,我認爲這不是個好主意,我只是想弄清楚什麼問題是:D遠程調試 – tonakai