0
public static void main(String[] args) throws IOException
{
   String fileloc = "src\\assignment12\\Areas.csv";
   List<data> list = new ArrayList<data>();
    try {
       BufferedReader br = new BufferedReader(new FileReader(fileloc));
       String line = null;
       String read = br.readLine();
       while (read != null){

        String temp[] = read.split(",");  

        list.add(new data(temp[0], temp[1], temp[2], temp[3], temp[4]));

     System.out.println(list);
       }


       br.close();
   }catch (IOException e){
       System.out.println("Error Reading FIle");
   }
}

my data class

public class data extends States{
private String state;
private String total;
private String land;
private String water;
private String waterperc;

public data(String state, String total, String land, String water, String waterperc){



    this.state = state;
    this.total = total;
    this.land = land;
    this.water = water;
    this.waterperc = waterperc;
}

public String state(){
    return state;
}

public void getState(String state){
    this.state = state;
}

public String total(){
    return total;
}

public void getTotal(String total){
    this.total = total;
   }

public String land(){
    return land;
}

public void getLand(String land){
    this.land = land;
}
public String water(){
    return water;
}

public void getWater(String water){
    this.water = water;
}
public String waterperc(){
    return waterperc;
}

public void getWaterperc(String waterperc){
    this.waterperc = waterperc;
}
}

I'm pretty new at coding so please be nice haha!

When i try to convert the array from the second to the last, it won't let me convert the data from my String to double.

Am I missing something or am I just completely just not understanding?

5
  • when i try to convert the array from the second to the last: what does that mean? What exact and complete error do you get? Hint: how many times do you call readLine()? Commented Apr 30, 2017 at 15:54
  • Possible duplicate of JAVA - import CSV to ArrayList Commented Apr 30, 2017 at 15:54
  • I guess it should be while((read = br.readLine()) != null)! And what's the use of variable line? Commented Apr 30, 2017 at 16:01
  • 1
    Maybe you need to use type Object // ArrayList<Object> list = new ArrayList<Object>(); // for your list. It's more common approach Commented Apr 30, 2017 at 16:20
  • well the csv file is like this North Carolina,140,130,13,10 Indiana,94,93,1.5,1.6 Wyoming,250,250,1.9,0.70 Commented May 1, 2017 at 1:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.