mlahbib
Messages postés6Date d'inscriptionjeudi 22 avril 2010StatutMembreDernière intervention 1 décembre 2011
-
27 sept. 2011 à 23:13
cs_Julien39
Messages postés6414Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention29 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:
Index out of bounds
Index 0 out of bounds for length 0 - Meilleures réponses
Index 1 out of bounds for length 1 - Meilleures réponses
cs_Julien39
Messages postés6414Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention29 juillet 2020369 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.