Accès global aux arguments
Bonjour,
Je n'arrive pas à accéder/modifier certaines variables de mon programme java :
Voici la structure globale de mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
public class MaClassePrincipale {
private static final String CHAINE_MODE1_1 = "11";
private static final String CHAINE_MODE1_2 = "12";
private static final String CHAINE_MODE2_1 = "21";
private static final String CHAINE_MODE2_2 = "22";
private static String chaine_mode_1;
private static String chaine_mode_2;
public static class MaClasseStatique1
{
public void MaFonction1()
throws IOException, InterruptedException
{
//CODE
}
}
public static class MaClasseStatique2
{
public void MaFonction2()
throws IOException, InterruptedException
{
//CODE
}
}
public static void main(String[] args) throws Exception
{
if ( args[0].CompareTo("mode1") == 0 )
{
chaine_mode_1=CHAINE_MODE1_1;
chaine_mode_2=CHAINE_MODE1_2;
}
else
{
chaine_mode_1=CHAINE_MODE2_1;
chaine_mode_2=CHAINE_MODE2_2;
}
Job job = new Job(FConf, "monjob");
job.setJarByClass(MaClassePrincipale.class);
job.setMapperClass(MaClasseStatique1.class);
job.setReducerClass(MaClasseStatique2.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(FInputPath));
FileOutputFormat.setOutputPath(job, new Path(FOutputPath));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
} |
La valeur de chaine_mode_1 et chaine_mode_2 dans MaFonction1 et MaFonction2 sont null, il y a une subtilité que je n'ai pas compris, pourriez vous m'expliquer pourquoi svp?
Merci d'avance!
voici, mais bon je doute que ca soit un problème de visibilité
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| public class MaClassePrincipale {
private static final String CHAINE_MODE1_1 = "11";
private static final String CHAINE_MODE1_2 = "12";
private static final String CHAINE_MODE2_1 = "21";
private static final String CHAINE_MODE2_2 = "22";
private static String chaine_mode_1;
private static String chaine_mode_2;
public static class MaClasseStatique1
{
public void MaFonction1()
throws IOException, InterruptedException
{
//CODE
System.out.println(chaine_mode_1);
//->> affiche null
System.out.println(chaine_mode_2);
//->> affiche null
}
}
public static class MaClasseStatique2
{
public void MaFonction2()
throws IOException, InterruptedException
{
//CODE
//->> affiche null
System.out.println(chaine_mode_1);
//->> affiche null
System.out.println(chaine_mode_2);
}
}
public static void main(String[] args) throws Exception
{
if ( args[0].CompareTo("mode1") == 0 )
{
chaine_mode_1=CHAINE_MODE1_1;
chaine_mode_2=CHAINE_MODE1_2;
}
else
{
chaine_mode_1=CHAINE_MODE2_1;
chaine_mode_2=CHAINE_MODE2_2;
}
Job job = new Job(FConf, "monjob");
job.setJarByClass(MaClassePrincipale.class);
job.setMapperClass(MaClasseStatique1.class);
job.setReducerClass(MaClasseStatique2.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(FInputPath));
FileOutputFormat.setOutputPath(job, new Path(FOutputPath));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
} |