2017-10-04 78 views
-4

你能幫我嗎..我需要一個簡單的程序來預處理一些數據到數據挖掘中,而我試圖用java來做這件事,但是它會給出數組以外的債券異常,你幫我修理它?謝謝。數組讀取文件時出現債券異常

該任務非常簡單,只需讀取兩個文件,然後寫出所需信息的第三個文件即可。在Java中

 try { 
      while ((linhapessoa = pessoain.readLine())!= null) 
      { 
       String[] splitlinhapessoa = linhapessoa.split(","); 
       String pessoaId = splitlinhapessoa[1] + splitlinhapessoa[2] + splitlinhapessoa[3] + splitlinhapessoa[4] 
       + splitlinhapessoa[23]; 
       String domclId = splitlinhapessoa[1] + splitlinhapessoa[2] + splitlinhapessoa[3] + splitlinhapessoa[4]; 

       while ((linhaconsumo = consumoin.readLine())!= null) 
       { 
       String[] splitlinhaconsumo = linhaconsumo.split(","); 
       String con_pessoaId = splitlinhaconsumo[1] + splitlinhaconsumo[2] + splitlinhaconsumo[3] + 
       splitlinhaconsumo[4] + splitlinhaconsumo[21] ; 
       String con_domclId = splitlinhaconsumo[1] + splitlinhaconsumo[2] + splitlinhaconsumo[3] + splitlinhaconsumo[4]; 




       if (pessoaId.equals(con_pessoaId)) 
       { 
        if (((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "801"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1101"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1301"))| 
         ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "2401"))| 
         ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "2402"))) 
         {cons_celular = "1"; val_cons_celular = splitlinhaconsumo[11];} 

        if (((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "801"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "901"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1101"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1401"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "401"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "501"))) 
         {cons_telfixo = "1"; val_cons_telfixo = splitlinhaconsumo[11];} 

        if ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "1101")) 
        { 
        cons_shows = "1"; val_cons_shows = splitlinhaconsumo[11]; 
        } 

        if (((splitlinhaconsumo[9] == "13") && (splitlinhaconsumo[10] == "1701"))| 
         ((splitlinhaconsumo[9] == "15") && (splitlinhaconsumo[10] == "2701"))| 
         ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "5701"))| 
         ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "2601"))| 
         ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "901")))      
         {cons_dvd = "1"; val_cons_dvd = splitlinhaconsumo[11]; } 

        if (((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "502"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "503"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "504"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "505"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "506"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "801"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "901"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1001"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1301"))| 
         ((splitlinhaconsumo[9] == "6") && (splitlinhaconsumo[10] == "1401")))      
         {cons_internet = "1"; val_cons_internet = splitlinhaconsumo[11]; } 

        if ((splitlinhaconsumo[9] == "28") && (splitlinhaconsumo[10] == "101")) 
        {cons_cinema = "1"; val_cons_cinema = splitlinhaconsumo[11]; } 




        String linhasaida = linhapessoa + "," + cons_celular + "," + val_cons_celular + "," + cons_telfixo+ "," + val_cons_telfixo + 
        "," + cons_shows + "," + val_cons_shows + "," + cons_dvd + "," + val_cons_dvd + "," + cons_internet + "," + val_cons_internet 
          + "," + cons_cinema + "," + val_cons_cinema; 

        processado.write(linhasaida); 

       } 
+2

您可以粘貼完整的錯誤消息和堆棧跟蹤嗎?你能用較小的代碼樣本重現問題嗎? –

+3

不要用'=='比較字符串。並向我們​​展示一個[mcve]。通過一個巨大的牆上代碼是煩人的。 – Gendarme

+0

'閱讀文件'與此無關。保持相關。 – EJP

回答

0

陣列(在大多數但不是所有語言)是0索引。

因此,您的第一列是0,而不是1.