Array Index Out Of Bound Exception

Résolu
mlahbib Messages postés 6 Date d'inscription jeudi 22 avril 2010 Statut Membre Dernière intervention 1 décembre 2011 - 27 sept. 2011 à 23:13
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 - 29 sept. 2011 à 08:59
Bonjour
je suis debutant dans le domaine de java
ceci est mon code. Lorsque j'execute j'obtient l'exeption suivante
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at driver.Driver.main(Driver.java:17)
est ce que qq peut m'aider
Merci d'avance

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import exemple1.File1;
import exemple2.File2;
public class Driver
{
public static void main(String[] args)
{
File driverFile = new File(args[0]);
int rang = Integer.parseInt(args[0]);
try
{
BufferedReader input = new BufferedReader(new FileReader(driverFile));
String line = input.readLine();
if (line == null)
System.exit(0); // Nothing in the file = nothing to do.
if (line.equalsIgnoreCase("exepl1"))
File1.parseDriverFile(driverFile, rang);
else if (line.equalsIgnoreCase("exepl2"))
File2.parseDriverFile(driverFile, rang);
}
catch (IOException e)
{
System.out.println("Problems working with driver file.");
e.printStackTrace();
}
}
}
A voir également:

5 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
29 sept. 2011 à 08:59
Quand tu feras un .jar exécutable, tu pourras spécifier les variables contenues dans args. Pour l'instant, je te conseil de remplir ce tableau à la main dans le code.
3