Bonsoir.
J'essai en vain de charger une page html d'un site dans un thread mais impossible sa me renvoi ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
Exception in thread "Thread-2" java.lang.NullPointerException
	at net.minecraft.OckraftThread.run(OckraftThread.java:18)
Voici ma classe :
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
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
 
import javax.swing.JEditorPane;
 
public class OckraftThread extends Thread {
	  private String param;
	  private JEditorPane recup;
 
	  public OckraftThread(String param) {
		 this.param = param;
	  }
	  public void run() {
		 try {
			recup.setPage(new URL(param));
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  }
 
	  public String getResult()
	  {
		  return recup.getText();
	  }
}
et voici son appel :
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
		JEditorPane editorPane = new JEditorPane();
		editorPane.setContentType("text/html"); 
		editorPane.setText("<html><body><center>Loading update news..</center><br><br><br><br><br><br><br></body></html>");
		editorPane.setBackground(Color.DARK_GRAY);
		editorPane.setEditable(false);
		editorPane.setMargin(null);
		JScrollPane scroll = new JScrollPane(editorPane);
		scroll.setPreferredSize(new Dimension(100, 150));
		scroll.setBorder(new MatteBorder(1, 0, 0, 0, Color.WHITE));
		try
		{
			OckraftThread recupt = new OckraftThread("http://www.site.com");
			recupt.start();
			editorPane.setText(recupt.getResult());
		}catch (Exception e) {
			editorPane.setText("<html><body><center>Erreur de chargement</center><br><br><br><br><br><br><br></body></html>");
		}
Merci beaucoup pour l'aide a venir..