IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Concurrence et multi-thread Java Discussion :

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 10


Sujet :

Concurrence et multi-thread Java

  1. #1
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 10
    j'ai un petit souci avec mon bout de code.
    Je récupère des données provenant d'un fichier txt.
    Code qui pose problème:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    private void parseDataLine(String line) {
            System.out.println("index :" + index );
            for (int j=0; j<index ; j++){
                System.out.println("j :" + j   + "  " + line.substring(indexTable[0][j], indexTable[1][j]).trim());
                if (j==0) values = values + "'" + line.substring(indexTable[0][j], indexTable[1][j]).trim()+ "'" ;
               else values = values + "," + "'" + line.substring(indexTable[0][j], indexTable[1][j]).trim()+ "'" ;
            }
            values = values + ");";
         }
    c'est celui qui est en gras.
    données posant problème:
    87300729022009873007290216/12/200916/12/2009SCI Mdouagon 000000000000160620 01 20080020307M48732008312410970 000
    87300730562009873007305618/12/200918/12/2009CISSE Mamadou 0000000000000600007246317 03ECO20089913766D48732008312411050 000
    87300731932009873007319322/12/200922/12/2009SCI Mdouagon 000000000000402600 01 20080020307M48732008312410970 000
    87300733812009873007338129/12/200929/12/2009SCI Mdouagon 0000000000001750007648441 03SGB20080020307M48732008312410970 000
    87500735232009875007352317/12/200917/12/2009MR ET MADAME SIDIBE VAKABA 0000000000000427507364481 03ECO20094105331T48752009320446639 000
    87500735252009875007352517/12/200917/12/2009MR ET MADAME SIDIBE VAKABA 0000000000000427507364481 03ECO20094105331T48752009320446637 000
    96900631732009969006317321/12/200921/12/2009BOSSON ATTIA 0000000000002457000081730 03BIA20098805280P49692009320446276 000
    la ligne qui pose problème est en gras
    Tableau des index:
    column :reg_num_reg index1 :0 index2 :10
    column :reg_num_pce index1 :10 index2 :24
    column :reg_dat_rec index1 :24 index2 :34
    column :reg_dat_val index1 :34 index2 :44
    column :reg_part_vers index1 :44 index2 :94
    column :reg_mont_reg index1 :94 index2 :112
    column :reg_num_chq index1 :112 index2 :132
    column :reg_cod_mod index1 :132 index2 :134
    column :reg_cod_baq index1 :134 index2 :137
    column :reg_annee_reg index1 :153 index2 :157
    column :reg_cont_ncc index1 :141 index2 :149
    column :reg_cod_imp index1 :149 index2 :150
    column :reg_cod_pc index1 :150 index2 :153
    column :reg_num_art index1 :153 index2 :169
    column :reg_cod_com index1 :169 index2 :172
    Affichage des données :
    index :15
    j :0 8730073056
    j :1 20098730073056
    j :2 18/12/2009
    j :3 18/12/2009
    j :4 CISSE Mamadou
    j :5 000000000000060000
    j :6 7246317
    j :7 03
    j :8 ECO
    j :9 2008
    j :10 9913766D
    j :11 4
    j :12 873
    j :13 2008312411050
    j :14 000
    index :15
    j :0 8730073193
    j :1 20098730073193
    j :2 22/12/2009
    j :3 22/12/2009
    j :4 SCI Mdouagon
    j :5 000000000000402600
    j :6
    j :7 01
    j :8
    j :9 2008
    j :10 0020307M
    j :11 4
    j :12 873
    j :13 2008312410970
    j :14 000
    index :15
    j :0 8730073381
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 10
    j :1 20098730073381
    at java.lang.String.substring(String.java:1934)
    j :2 29/12/2009
    at mis.ui.component.io.FilesScanner.parseDataLine(FilesScanner.java:135)
    at mis.ui.component.io.FilesScanner.readDataFile(FilesScanner.java:70)

    j :3 29/12/2009
    j :4 SCI Mdouagon
    at mis.ui.component.io.FilesScanner.<init>(FilesScanner.java:35)
    at mis.ui.component.io.FilesScanner.main(FilesScanner.java:143)

    j :5 000000000000175000
    j :6 7648441
    j :7 03
    j :8 SGB
    j :9 2008
    j :10 0020307M
    j :11 4
    j :12 873
    j :13 2008312410970
    j :14 000
    index :15
    j :0 8750073523
    j :1 20098750073523
    j :2 17/12/2009
    j :3 17/12/2009
    j :4 MR ET MADAME SIDIBE VAKABA
    j :5 000000000000042750
    j :6 7364481
    j :7 03
    j :8 ECO
    j :9 2009
    j :10 4105331T
    j :11 4
    j :12 875
    j :13 2009320446639
    j :14 000
    index :15
    j :0 8750073525
    j :1 20098750073525
    j :2 17/12/2009
    j :3 17/12/2009
    j :4 MR ET MADAME SIDIBE VAKABA
    j :5 000000000000042750
    j :6 7364481
    j :7 03
    j :8 ECO
    j :9 2009
    j :10 4105331T
    j :11 4
    j :12 875
    j :13 2009320446637
    j :14 000
    index :15
    j :0 9690063173
    j :1 20099690063173
    j :2 21/12/2009
    j :3 21/12/2009
    j :4 BOSSON ATTIA
    j :5 000000000000245700
    j :6 0081730
    j :7 03
    j :8 BIA
    j :9 2009
    j :10 8805280P
    j :11 4
    j :12 969
    j :13 2009320446276
    j :14 000
    index :15
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    pourrais-tu modifier le code comme ci dessous en nous envoyer l'output? Merci


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    private void parseDataLine(String line) {
     
            System.out.println("index :" + index );
            for (int j=0; j<index ; j++){
                try{
                  System.out.println("j :" + j   + "  " + line.substring(indexTable[0][j], indexTable[1][j]).trim());
                  if (j==0) values = values + "'" + line.substring(indexTable[0][j], indexTable[1][j]).trim()+ "'" ;
                  else values = values + "," + "'" + line.substring(indexTable[0][j], indexTable[1][j]).trim()+ "'" ;
                } catch (StringIndexOutOfBoundsException e){
                  System.out.println("probleme with <"+line+"> at loop j="+j);
                  e.printStackTrace();
                  throw e; 
                }
            }
            values = values + ");";
         }

  3. #3
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut
    j'ai fais ce que vous avez dit.
    Voici l'output
    index :15
    j :0 8750073525
    j :1 20098750073525
    j :2 17/12/2009
    j :3 17/12/2009
    j :4 MR ET MADAME SIDIBE VAKABA
    j :5 000000000000042750
    j :6 7364481
    j :7 03
    j :8 ECO
    j :9 2009
    j :10 4105331T
    j :11 4
    j :12 875
    java.lang.StringIndexOutOfBoundsException: String index out of range: 10
    j :13 2009320446637
    j :14 000
    index :15
    at java.lang.String.substring(String.java:1934)
    j :0 9690063173
    j :1 20099690063173
    at mis.ui.component.io.FilesScanner.parseDataLine(FilesScanner.java:146)
    j :2 21/12/2009
    j :3 21/12/2009
    j :4 BOSSON ATTIA
    j :5 000000000000245700
    at mis.ui.component.io.FilesScanner.readDataFile(FilesScanner.java:70)
    j :6 0081730
    j :7 03
    j :8 BIA
    j :9 2009
    j :10 8805280P
    j :11 4
    at mis.ui.component.io.FilesScanner.<init>(FilesScanner.java:35)
    j :12 969
    j :13 2009320446276
    j :14 000
    at mis.ui.component.io.FilesScanner.main(FilesScanner.java:159)
    index :15
    probleme with <> at loop j=0
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 10
    at java.lang.String.substring(String.java:1934)
    at mis.ui.component.io.FilesScanner.parseDataLine(FilesScanner.java:146)
    at mis.ui.component.io.FilesScanner.readDataFile(FilesScanner.java:70)
    at mis.ui.component.io.FilesScanner.<init>(FilesScanner.java:35)
    at mis.ui.component.io.FilesScanner.main(FilesScanner.java:159)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

  4. #4
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut
    vu qu'il affiche toujours l'erreur je me suis dis qu'il s'agissait peut être d'une ligne vide alors j'ai ajouté une condition sur la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    private void parseDataLine(String line) {
            if (line.trim().length()>0) {
               System.out.println("index :" + index );
               for (int j=0; j<index ; j++){
                   try{
                      System.out.println("j :" + j   + "  " + line.substring(indexTable[0][j], indexTable[1][j]).trim());
                      if (j==0) values = values + "'" + line.substring(indexTable[0][j], indexTable[1][j]).trim()+ "'" ;
                      else values = values + "," + "'" + line.substring(indexTable[0][j], indexTable[1][j]).trim()+ "'" ;
                   } catch (StringIndexOutOfBoundsException e){
                      System.out.println("probleme with <"+line+"> at loop j="+j);
                      e.printStackTrace();
                      throw e;
                   }
               }
            }
            values = values + ");";
         }
    et là je n'ai plus l'erreur.
    Je vous remercie pour votre aide

  5. #5
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par yLaplace Voir le message
    vu qu'il affiche toujours l'erreur je me suis dis qu'il s'agissait peut être d'une ligne vide
    Ce qui est confirmé par "probleme with <> at loop j=0"

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException ?
    Par freezerhm dans le forum Concurrence et multi-thread
    Réponses: 5
    Dernier message: 04/12/2007, 09h26
  2. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par Trint dans le forum Interfaces Graphiques en Java
    Réponses: 6
    Dernier message: 27/02/2007, 11h28
  3. Réponses: 8
    Dernier message: 11/05/2006, 19h32
  4. [JDIC]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par kedare dans le forum Concurrence et multi-thread
    Réponses: 4
    Dernier message: 06/05/2006, 22h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo