I am having a little trouble with my code. I have a hash map which has data. I want to get that data from the hash table and so far so good everything was working properly until I tried to get the coordinates of a point. I have made a class called "Segments" it contains a string "name" and an array of Doubles (longitude latitude). It is supposed to fill the variables with data from the hash table. In debug mode I saw the elements the longitude and latitude but it doesn't put them into the arrays I have specified and it prints out an error:
"ClassCastException: java.lang.Object[] cannot be cast to java.lang.Double"
Here is my code.
public class Segments
{
public String name;
public double[] latitude;
public double[] longitude;
public void Read(HashMap<String,Object> segment)
{
this.name = (String) segment.get("name");
Object[] coord = (Object[]) segment.get("coordinates");
try
{
for(int i = 0; i < coord.length; i++)
{
latitude[i] = (Double)coord[0];
longitude[i] = (Double)coord[1];
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Can you tell me what am I doing wrong and how to fix my code?
coord[0]
? – shayan pourvatan Feb 10 at 12:32