当前位置: 代码迷 >> J2EE >> 运行报错:java.lang.ArrayIndexOutOfBoundsException: 二
  详细解决方案

运行报错:java.lang.ArrayIndexOutOfBoundsException: 二

热度:768   发布时间:2016-04-17 23:40:09.0
运行报错:java.lang.ArrayIndexOutOfBoundsException: 2
package ie.dit.comp.lukejia.fyp.swn;

import java.io.BufferedReader;
import java.io.File;
    import java.io.FileReader;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.Vector;

    public class SWN3 {
        private String pathToSWN = "D:\\study\\Quarter1\\IRDM\\Project\\resource\\SWN.txt";
        private HashMap<String, Double> _dict;

        public SWN3(){

            _dict = new HashMap<String, Double>();
            HashMap<String, Vector<Double>> _temp = new HashMap<String, Vector<Double>>();
            try{
                BufferedReader csv =  new BufferedReader(new FileReader(pathToSWN));
                String line = "";           
                while((line = csv.readLine()) != null)
                {
                    String[] data = line.split("\t");
                    Double score = Double.parseDouble(data[2])-Double.parseDouble(data[3]);
                    String[] words = data[4].split(" ");
                    for(String w:words)
                    {
                        String[] w_n = w.split("#");
                        w_n[0] += "#"+data[0];
                        int index = Integer.parseInt(w_n[1])-1;
                        if(_temp.containsKey(w_n[0]))
                        {
                            Vector<Double> v = _temp.get(w_n[0]);
                            if(index>v.size())
                                for(int i = v.size();i<index; i++)
                                    v.add(0.0);
                            v.add(index, score);
                            _temp.put(w_n[0], v);
                        }
                        else
                        {
                            Vector<Double> v = new Vector<Double>();
                            for(int i = 0;i<index; i++)
                                v.add(0.0);
  相关解决方案