Bonjour,
J'ai un tableau que je remplis d'éléments divers, et je voudrais récupérer l'event double click sur une ligne de mon tableau (j'ai utilisé SWT.FULL_SELECTION) pour lancer une méthode qui me fera pop une autre fenêtre. Or j'ai une erreur.
Voilà le morceau de code concerné :
J'essaye de récuperer le contenu de la ligne sur laquelle on double click et de l'afficher, mais ca plante pendant l'éxecution (au moment ou je double click):
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 public class GuiSWT { ModeXML toto = new ModeXML(); static Display display = new Display(); Shell shell = new Shell(display, SWT.RESIZE | SWT.CLOSE | SWT.MIN ); public void mainWindow() { int k = 0; Table table = new Table(shell, SWT.FULL_SELECTION); String[] blabla; toto.initXML(); String[] titles = { "UserName", "Id" }; table.setHeaderVisible(true); for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) { TableColumn column = new TableColumn(table, SWT.NULL); column.setText(titles[loopIndex]); } while ((blabla = toto.displayXML(k)) != null) { TableItem item = new TableItem(table, SWT.NULL); item.setText(new String[]{blabla[0], blabla[1]}); System.out.println(blabla[0]); System.out.println(blabla[1]); k++; } for (int loopIndex1 = 0; loopIndex1 < titles.length; loopIndex1++) { table.getColumn(loopIndex1).pack(); } table.pack(); shell.pack(); table.addListener(SWT.MouseDoubleClick, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem)event.item; System.out.println(item.getText(0)); secondWindow(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
J'ai mis en rouge la ligne 56.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Exception in thread "main" java.lang.NullPointerException at GuiSWT$1.handleEvent(GuiSWT.java:48) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at GuiSWT.mainWindow(GuiSWT.java:56) at FirstWindow.main(FirstWindow.java:13)
Merci d'avance.
Cordialement,
Bdloul
Partager