简体   繁体   中英

can't find symbol error, java

I declared a global vector, and I'm trying to access it globally, but it throws an error.

It says cannot find symbol XArray or YArray.

The code I'm using (I've cut some of it out that I thought was not necessary):

public class Main {

    public static void main(String[] args) {

        String csvFile = "/Users/hherzberg/Desktop/testData.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

        ArrayList<Point3D> myPoints = new ArrayList<Point3D>();
        ArrayList<Double>  XArray = new ArrayList<Double>();
        ArrayList<Double> YArray = new ArrayList<Double>();
        try {
            int xcount=0;
            int ycount=0;

            double multiplied=0;
            br = new BufferedReader(new FileReader(csvFile));
            br.readLine();
            while ((line = br.readLine()) != null) {
                // use comma as separator
                String[] number = line.split(cvsSplitBy);
                double x = Double.parseDouble(number[0]);
                double y = Double.parseDouble(number[1]);
                XArray.add(x);
                YArray.add(y);
                Point3D p = new Point3D(x, y);
                myPoints.add(p);
                xcount+=1;
                ycount+=1;

                System.out.println(p);
            }
            for (int i=0; i<myPoints.size();i++)
            {
                multiplied+=Double.parseDouble(XArray(i))*Double.parseDouble(YArray(i+1));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

    }
}

Some help with this would be greatly appreciated.

Use below import at first line and it should work

import java.io.*;
import java.util.*;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM