findAdressResults with Java pb

wissam114
04-13-2007, 12:39 PM
Hi everybody,

I'm working on a java application using Mappoint and I have a problem with the "findAdressResults" method here is the code i wrote, but I don't know how to retrieve the location result:

FindResults fr;
Integer geousa=new Integer(MNPA83.GeoCountry.geoCountryUnitedStates);
Location objLoc1;
Variant index =new Variant(com.borland.dx.dataset.Variant.INT);
index.setInt(1);
fr=objMap.findAddressResults("359 WABASH AVE","BUFFALO"," ","NY","14217",geousa);
int nbfound=fr.getCount();
objLoc1=(Location)fr.getItem(index);


When I debug the program the variable nbfound=1, but I have an "java.lang.ClassCastException" for the last line of the code.
Please help me to correct the Error if you can,
Thanks in advance.

Wilfried
04-14-2007, 03:41 AM
Hi,

All items of the collection are not nececarly Location objects. The collection can have other types of object in it also. Possible that is the course for the exception. So you have to check first the type of the item before typecasting it.

wissam114
04-14-2007, 04:42 AM
Thanks Wilfried for your reply, The result's type is "stdobjref" so to solve the pb I replaced the Cast instruction by the following:


objLoc1= new Location(fr.getItem(index));


and I had the object Location I need.
If you have any other Solution please let me know.
Thanks again.

Wilfried
04-14-2007, 06:44 AM
Hi,

Yes will sure work if the returned item is a Location object, but what if it is a Pushpin or other object, then it will generate an exception.

I'm no Java specialist but maybe first store it in a new object, this will always work, then get the class of it and if it is a Location then I think you can typecast it. Something like this:

Object o = new Object(fr.getItem(index));
o.getClass() or o.isInstance() or o.getClass.getName()

I'm not sure if this will get you further.

 
Web mp2kmag.com
mapforums.com