1

次のようなテキスト ファイルがある場合:
10
100
99
99
96
96
92
92
91
88
87
86

最初の数値「10」は、テキスト ファイルに10 個の整数が含まれていることを意味し、2 番目の数値100は、テキスト ファイル内のすべての数値が100を超えないことを意味します。
私の目的は、テキストを読み、次のint data[][];ように記入することです:

data[0][0]=1    data[0][1]=99
data[1][0]=2    data[1][1]=99
data[2][0]=3    data[2][1]=96
data[3][0]=4    data[3][1]=96
data[4][0]=5    data[4][1]=92
data[5][0]=6    data[5][1]=92
data[6][0]=7    data[6][1]=91
data[7][0]=8    data[7][1]=88
data[8][0]=9    data[8][1]=87
data[9][0]=10   data[9][1]=86
cbin = 100 // bin capacity 
nbin = 10 // number of objects 

これは、インデックスの場合は最初に生で、アイテムの値または重みの場合は2番目であることを意味します..そしてint cbin = \\the second text's valueint nbin = \\the first text's value
スレッドで例外が発生するという問題

"AWT-EventQueue-0" java.lang.NullPointerException


これが私のコードです:

 public static int[][] data=null; \\ in the first of the document

       JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f= chooser.getSelectedFile();

        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(interface1.class.getName()).log(Level.SEVERE, null, ex);
        }
    try {
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();
        int i=0,j=0;
        while (line != null) {

            if(i==0){
                nbin= (int) Integer.parseInt(""+line);
                System.out.println(nbin);
            }
            else if (i==1) {
                cbin=(int) Integer.parseInt(""+line);
                System.out.println(cbin);
            }
          //  sb.append(line);
            line = br.readLine();
        if(i >= 2 && line != null){

               data[j][1]=(int) Integer.parseInt(line);
               data[j][0]=j;
               j++;

             }

            i++;

        }
          }   catch (IOException ex) {
            Logger.getLogger(interface1.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
        try {
            br.close();
        } catch (IOException ex) {
            Logger.getLogger(interface1.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

何か案は ??

4

2 に答える 2