Ben on t'a dit de regarder l'erreur, tu l'as fait, ensuite faut réfléchir deux secondes pour voir qu'il faut importer et ouvrir sa Javadoc pour voir que Collections c'est java.util.Collections.
Donc
Code:
1
2import java.util.Collections;
Version imprimable
Ben on t'a dit de regarder l'erreur, tu l'as fait, ensuite faut réfléchir deux secondes pour voir qu'il faut importer et ouvrir sa Javadoc pour voir que Collections c'est java.util.Collections.
Donc
Code:
1
2import java.util.Collections;
Merci de lire les tutoriaux, la javadoc, etc...Code:
1
2import java.util.Collections
(grillé :? )
erf désolé:( ba je vai tester tout ca encore merci :king:
bon ben j'ai toujours un problème : quand je lance mon prog et que j'éxécute la fenêtre qui génére mon tableau j'ai une erreur en exe :et voila ce que contient mon ArrayList :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 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.JTable$1.getRowCount(Unknown Source) at javax.swing.JTable.getRowCount(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.createTableSize(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(Unknown Source) at javax.swing.JComponent.getPreferredSize(Unknown Source) at javax.swing.JViewport.getViewSize(Unknown Source) at javax.swing.ScrollPaneLayout.preferredLayoutSize(Unknown Source) at java.awt.Container.preferredSize(Unknown Source) at java.awt.Container.getPreferredSize(Unknown Source) at javax.swing.JComponent.getPreferredSize(Unknown Source) at java.awt.GridLayout.preferredLayoutSize(Unknown Source) at java.awt.Container.preferredSize(Unknown Source) at java.awt.Container.getPreferredSize(Unknown Source) at javax.swing.JComponent.getPreferredSize(Unknown Source) at java.awt.FlowLayout.layoutContainer(Unknown Source) at java.awt.Container.layout(Unknown Source) at java.awt.Container.doLayout(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validateTree(Unknown Source) at java.awt.Container.validate(Unknown Source) at java.awt.Window.show(Unknown Source) at java.awt.Component.show(Unknown Source) at java.awt.Component.setVisible(Unknown Source) at ConsultListe.build(ConsultListe.java:46) at ConsultListe.<init>(ConsultListe.java:34) at ConsultCat.actionPerformed(ConsultCat.java:85) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Code:
1
2
3
4
5 listeHotels.add(resultat.getString("nom")); listeHotels.add(resultat.getInt("etoile")); listeHotels.add(resultat.getInt("chsimples")); listeHotels.add(resultat.getInt("chdoubles")); listeHotels.add(resultat.getInt("prix"));
y'a personne qu'aurait une idée pour que je puisse remplir un tableau a partir d'une ArrayList???:roll:
Salut,
Comme je te l'ai dit precedement moi je fait :
Ce code fontionne dans mon soft sachant que hosts est un ArrayList et s est un String[]Code:
1
2 Collections.addAll(hosts, s);
Attention dans ton arrayList les type son homogène ou non ?
a ben non moi justement à la place de ton s moi c'est une tableau d'object data[][] c'est pour ca a mon avis que cela ne fonctionne pas.De plsu les type ne sont pas homogène puisque j'ai un String et 4 int à chaque fois. Pour créer mon tableau jai utilisé le tutorial de sun ==>http://java.sun.com/docs/books/tutor...nts/table.html mais c'est quand meme bizarre que pour remplir un tableau il faut savoir à l'avance ce qui va s'y placer :roll:
et lorsque j'utiliseJe ne peut utiliser ma variable après pour construire mon tableau parce qu'il ne me la reconnait plus:?Code:
1
2
3
4
5 for(int i=0;i<hot.size();i=i+2){ Object[][] data = { {hot.get(i),hot.get(i+1),hot.get(i+2),hot.get(i+3),hot2.get(i+1)}, }; }
bon ben c'est bon j'ai trouvé voila le code por ceux qui auraient le meme problèmeCode:
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 class Table extends JPanel { private Connection connection; private String dest; private int i=0,j=0; private String type; public Table(String dest,String type) { super(new GridLayout(1,0)); this.dest=dest; this.type=type; ConnectDB conec = new ConnectDB(); connection=conec.connectionBase(); Hotels hot1 = new Hotels(dest); ArrayList hotel = hot1.chercheHotels(connection); Object[][] data = new Object[hotel.size()/5][5]; String[] columnNames = {"Nom Hotel", "Etoiles", "Chambres Simples", "Chambres Doubles", "prix" }; for(i=0;i<hotel.size()/5;i++){ for(j=0;j<5;j++){ data[i][j] = hotel.get((i*5)+j); } } hotel.clear(); JTable table = new JTable(data,columnNames); table.setPreferredScrollableViewportSize(new Dimension(500,100)); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane); }}}