question

$$anonymous$$ avatar image
0 Likes"
$$anonymous$$ asked ·

Always getting "Object reference not set to an Instance" for shippingInfo in Finding API

Hello All, I 'm developing an application which will search for a product & retrieve all details like sellerInfo,shippingInfo,price,etc...However ,I'm getting error "Object reference not set to an instance of an object" while retrieving seller username & shippingInfo with the following syntax: This is for shipping cost: SearchItem[] items = response.searchResult.item; double shippingcost=items[i].shippingInfo.shippingServiceCost.Value. This is for sellerInfo: string sellerInfo = items[i].sellerInfo.sellerUserName; Please help,The control is going directly to catch block & raising exception. I tried checking for the null using if condition but no success its raising exception.
finding apic#
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
$$anonymous$$ avatar image
0 Likes"
$$anonymous$$ answered ·
I solved this Myself.What I did is I created an Object of shipping info like the above: string selleruname; double shippingcost; SellerInfo si = new SellerInfo(); ShippingInfo ship = new ShippingInfo(); si = items[i].sellerInfo; if (si == null) { selleruname = "Not Present"; } else { selleruname=si.sellerUserName; } ship = items[i].shippingInfo; if (ship.shippingServiceCost == null) { shippingcost = 0.0; } else { shippingcost = ship.shippingServiceCost.Value; }
· Share
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.