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....
airport[4]is"EVE"? If yes, then you need to check for that before usingDouble.parseDouble(). It cannot parse""or"EVE"... Why is theString"EVE"returned when you query numeric values?