I am trying to read the data from CSV file. everything works fine but when i try to read the data for longitude and latitude. it gives me an below error message.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yogi.guestlogix/com.example.yogi.guestlogix.MainActivity}: java.lang.NumberFormatException: Invalid double: "EVE"
Caused by: java.lang.NumberFormatException: Invalid double: "EVE"**
MainActivity.java
//Airports data begin
InputStream isss = getResources().openRawResource(R.raw.airports);
BufferedReader readerss = new BufferedReader(
new InputStreamReader(isss, Charset.forName("UTF-8"))
);
String liness = "";
//for airports.csv
try {
readerss.readLine();
while ((liness = readerss.readLine()) != null) {
//split by ',' first
String[] airport = liness.split(",");
//Read the data
AirportsData airdata = new AirportsData();
airdata.setAirportname(airport[0]);
airdata.setAirportcity(airport[1]);
airdata.setAirportcountry(airport[2]);
airdata.setAirportIATAcode(airport[3]);
//airdata.setAirportlang(Double.parseDouble(airport[4]));
//airdata.setAirportlat(Double.parseDouble(airport[5]));
AirportsDatas.add(airdata);
}
} catch (IOException e) {
Log.wtf("My Activity", "Reading data file error " + liness, e);
e.printStackTrace();
}
Log.d("Airline", "name is " + AirportsDatas);
AirportsData.java
public double getAirportlang(double airportlang) {
return airportlang;
}
public void setAirportlang(double airportlang) {
this.airportlang = airportlang;
}
public double getAirportlat( ) {
return airportlat;
}
public void setAirportlat(double airportlat) {
this.airportlat = airportlat;
}
@Override
public String toString() {
return "AirportsData{" +
"airportname='" + airportname + '\'' +
", airportcity='" + airportcity + '\'' +
", airportcountry='" + airportcountry + '\'' +
", airportIATAcode='" + airportIATAcode + '\'' +
", airportlang=" + airportlang +
", airportlat=" + airportlat +
'}';
}
**Any solution for this problem would be greatly appreciated....
I think the problem is that airport[4] & airport[5] might not be the lon and lat of the airport. If these field contain alpha characters [a-z] you will get an numberFormatException. Can you add the the output when you print airport like:
to the question? Than we will be better able to help you