bonsoir à tous,
voila mon probleme:
j'ai une classe java dans laquelle j'ai mon Main et un ActionPerformed (qui vient lorsqu'on clique sur un bouton).
Ds le main, j'ai mis un tableau (déclaration et construction).
Mais j'en ai aussi besoin dans mon actionPerformed, mais je n'arrive pas à placer la declaration convenablement pour ne pas avoir des erreurs. Voici mon code:
public class Test extends javax.swing.JFrame {
Dans ce cas, j'ai 2 erreurs dans le ActioPerformed car le tableau temp n'est pas défini!
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
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 static int i; static int max; /** Creates new form TestLireExcel */ public TestLireExcel() { initComponents(); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String mot; mot=TextMot.toString(); FileWriter ecrivain; int c; ecrivain = new FileWriter("fichier.txt"); ecrivain.write("import class\n"); for (i=0;i<max;i++){ if(temp[i][1].equals(mot)){ ecrivain.write(temp[i][2]); } ecrivain.close(); } } /** * @param args the command line arguments */ public static void main(String args[]) throws IOException { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TestLireExcel().setVisible(true); } }); //creation d'une matrice dans laquelle on va mettre les mots' String[] temp; temp=new String[100]; String[][] lexique; lexique = new String[100][2]; ... for (i=0;i<max;i++){ StringTokenizer st = new StringTokenizer(temp[i],";"); lexique[i][1]=st.nextToken(); lexique[i][2]=st.nextToken(); } for (i=0;i<max;i++){ System.out.println(lexique[i][1]); System.out.println(lexique[i][2]); } }
Si je les déclare avant (là où j'ai mis le static i et max, j'ai aussi des erreurs pour:
temp=new String[100];
lexique = new String[100][2];
voici l'erreur:
Test.java:19: <identifier> expected
temp=new String[100];
Test.java:21: <identifier> expected
lexique = new String[100][2];
Comment regler ce probleme?
MERCI
Partager