Salut !!!
Voilà, j'essais de lire dans un fichier texe et lors du lancement de l'application, on me dit NullPointerException, help me !!!
Voici, le code :
import javax.swing.JFrame;
import java.awt.Dimension;
import java.io.*;
import javax.swing.*;
public class Swing01 extends JFrame{
JLabel label = new JLabel();
public String[] tab;
Recherche rech = new Recherche();
public static void main(String args[]) throws IOException{
new Swing01();
}
public Swing01() throws IOException{
initGUI();
}
public void initGUI() throws IOException{
label.setBounds(0,0,200,200);
this.getContentPane().add(label);
this.setSize(150,150);
this.setVisible(true);
tab = rech.recherche("truc.txt","flo",5);
label.setText(tab[0]);
}
}
class Recherche{
public String[] flo;
public boolean fin;
public int i;
public String[] recherche(String fichier, String chaine, int sensibilite) throws IOException{
RandomAccessFile f = new RandomAccessFile(fichier,"rw" );
fin = false;
i = 0;
while (fin != true) {
try{
String lu = f.readLine();
if (lu.equals(chaine)){
flo[i++] = lu;
}
}
catch(EOFException e){
fin = true;
}
}
return flo;
}
}
Merci beaucoup !!!