java null指针异常,地图填充问题?

时间:2014-11-04 16:09:43

标签: java nullpointerexception

更新:

  

公共类HistoryJFrame扩展了javax.swing.JFrame {

private List<Patient> patientList;
private Map<Patient, Map<String, List<Double>>> patientData;
private List<Integer> score;
public HistoryJFrame() throws IOException {
    initComponents();


    //set window in the center of the screen
    //Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    //Determine the new location of the window
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;

    //Move the window
    this.setLocation(x, y);



    patientData = new HashMap<Patient, Map<String, List<Double>>>();

    String csvFile1 = "data/patientList.csv";
    BufferedReader br = null;

    patientList = new ArrayList<Patient>();

    try {

        br = new BufferedReader(new FileReader(csvFile1));
        br.readLine();
        String line1 = null;
        while ((line1 = br.readLine()) != null) {
            String[] patient = line1.split(",");
            int bedNum = Integer.parseInt(patient[0]);
            Patient patientObj = new Patient(bedNum, patient[1], patient[2], patient[3], patient[4], 0, 0, 0, 0);

            patientList.add(patientObj);

        }

        br.close();

    } catch (FileNotFoundException e) {
        System.out.println(e);
    } catch (IOException e) {
        System.out.println(e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                System.out.println(e);
            }
        }
    }
    parseData();

    for (int i = 0; i < patientList.size(); ++i) {


        String comboName = patientList.get(i).getFistName() + " " + patientList.get(i).getLastName();
        jComboBoxNames.addItem(comboName);

    }

    jComboBoxNames.requestFocus();



    this.addMouseListener(new MyMouse());


    Patient p = null;
    int i = 0;
    for (i = 0; i < patientList.size(); ++i){

        p = patientList.get(i);

        Map<String, List<Double>> pData = patientData.get(p);
        List<Double> pressRate = pData.get("BP");
        Double bloody = pressRate.get(pressRate.size() - 1);
        System.out.println(bloody);

        System.out.println(p);

    }

}

所以看起来它是空的。我正在解析csv文件中的信息,我知道这是有效的,因为我测试了它。似乎我在某种程度上未能正确地将信息传递到我的Map中,但我无法弄清楚我做错了什么!

数据结构:

private void parseData() {
    int i = 0;
    Patient p = null;
    for (i = 0; i < patientList.size(); ++i) {
        p = patientList.get(i);
        String csvFile = null;
        BufferedReader br = null;

        if (p == patientList.get(0)) {
            csvFile = "data/Alice_Bailey_20141011091022.csv";
        }
        if (p == patientList.get(1)) {
            csvFile = "data/Charlie_Dean_20141013103445.csv";
        }
        if (p == patientList.get(2)) {
            csvFile = "data/Elise_Foster_20141013122956.csv";
        }
        if (p == patientList.get(3)) {
            csvFile = "data/Grace_Hughes_20141013161902.csv";
        }
        if (p == patientList.get(4)) {
            csvFile = "data/Ian_Jones_20141013142915.csv";
        }
        if (p == patientList.get(5)) {
            csvFile = "data/Kelly_Lawrence_201410141532.csv";
        }

        try {
            br = new BufferedReader(new FileReader(csvFile));
            br.readLine();
            String line1 = null;

            while ((line1 = br.readLine()) != null) {
                String[] patient = line1.split(",");

                Double timeStamp = Double.parseDouble(patient[0]);
                Double breathR = Double.parseDouble(patient[1]);
                Double spo2 = Double.parseDouble(patient[2]);
                Double temP = Double.parseDouble(patient[3]);
                Double systolic = Double.parseDouble(patient[4]);
                Double heartR = Double.parseDouble(patient[5]);
                createDataStrut(p, timeStamp, breathR, spo2, temP, systolic, heartR);
            }
            br.close();
        } catch (FileNotFoundException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    System.out.println(e);
                }
            }
        }
    }
}

private void createDataStrut(Patient p, Double timeStamp, Double breathR, Double spo2, Double temP, Double systolic, Double heartR) {

    patientData = new HashMap<Patient, Map<String, List<Double>>>();

    if (patientData.get(p) == null) {

        patientData.put(p, new HashMap<String, List<Double>>());

        Map<String, List<Double>> data = patientData.get(p);


        List<Double> tStampList = new ArrayList<Double>();
        data.put("TS", tStampList);

        List<Double> bRateList = new ArrayList<Double>();
        data.put("BR", bRateList);

        List<Double> oRateList = new ArrayList<Double>();
        data.put("O2", oRateList);

        List<Double> pRateList = new ArrayList<Double>();
        data.put("BP", pRateList);

        List<Double> hRateList = new ArrayList<Double>();
        data.put("HR", hRateList);

        List<Double> tRateList = new ArrayList<Double>();
        data.put("TP", tRateList);
    }

    Map<String, List<Double>> data = patientData.get(p);

    List<Double> tStamp = data.get("TS");
    tStamp.add(timeStamp);

    List<Double> breathRate = data.get("BR");
    breathRate.add(breathR);

    List<Double> oxeyRate = data.get("O2");
    oxeyRate.add(spo2);

    List<Double> pressRate = data.get("BP");
    pressRate.add(systolic);

    List<Double> heartyRate = data.get("HR");
    heartyRate.add(heartR);

    List<Double> tempyRate = data.get("TP");
    tempyRate.add(temP);
}

0 个答案:

没有答案