Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14330 > unrolled thread
| Started by | Luiss <luiss@aol.com> |
|---|---|
| First post | 2012-05-06 12:03 +0200 |
| Last post | 2012-05-06 20:43 -0700 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
Help with JTable ... ClassCastException Luiss <luiss@aol.com> - 2012-05-06 12:03 +0200
Re: Help with JTable ... ClassCastException Luiss <luiss@aol.com> - 2012-05-07 00:18 +0200
Re: Help with JTable ... ClassCastException Roedy Green <see_website@mindprod.com.invalid> - 2012-05-06 19:14 -0700
Re: Help with JTable ... ClassCastException Lew <noone@lewscanon.com> - 2012-05-06 20:43 -0700
| From | Luiss <luiss@aol.com> |
|---|---|
| Date | 2012-05-06 12:03 +0200 |
| Subject | Help with JTable ... ClassCastException |
| Message-ID | <4fa64c84$0$1377$4fafbaef@reader2.news.tin.it> |
Hi all,
I'm writing a GUI to show a JTable cointaining data from a db table
(after I'll add also buttons to Add, Update and Delete rows). I need to
have different table fields and not only strings.
I've used Hibernate to do the select and then passed the list to a
Vector containing ConfigPersonale objects (my table bean).
I get this exception running the GUI:
********************************
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
com.ale.ts.persistence.ConfigPersonale cannot be cast to java.util.Vector
at
javax.swing.table.DefaultTableModel.justifyRows(DefaultTableModel.java:251)
at
javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.java:207)
at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:142)
at
com.ale.ts.view.ConfigPersonaleFrame$1.<init>(ConfigPersonaleFrame.java:42)
at
com.ale.ts.view.ConfigPersonaleFrame.<init>(ConfigPersonaleFrame.java:43)
at com.ale.ts.view.TS_UI$3.actionPerformed(TS_UI.java:100)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:809)
at
javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:850)
at java.awt.Component.processMouseEvent(Component.java:6290)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6055)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4653)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:621)
at java.awt.EventQueue$2.run(EventQueue.java:619)
at java.security.AccessController.doPrivileged(Native Method)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
********************************
****************************************
public class ConfigPersonaleFrame extends JFrame {
private JPanel contentPane;
private QueryConfigPersonale queryConfpers = new QueryConfigPersonale();
private JTable table;
public ConfigPersonaleFrame() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
setAlwaysOnTop(true);
setTitle("Configurazione Personale");
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
table = new JTable();
String[] columnNames_a = {"A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q"};
Vector<String> columnNames = new
Vector<String>(Arrays.asList(columnNames_a));
Vector<ConfigPersonale> dataTable = queryConfpers.getConfigPersonale();
table.setModel(new DefaultTableModel(
dataTable, columnNames) {
Class[] columnTypes = new Class[] {
Integer.class, String.class, String.class, Double.class,
Double.class, Integer.class, Double.class, String.class, Double.class,
Double.class, Double.class, Double.class, Double.class, Double.class,
Double.class, Boolean.class, Timestamp.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
});
contentPane.add(table);
//TODO: Add + Update + Delete
}
}
*********************************************
public class QueryConfigPersonale {
private Session session;
private Query query;
private List<ConfigPersonale> configPersList;
//select * from ConfigPersonale
@SuppressWarnings("unchecked")
public Vector<ConfigPersonale> getConfigPersonale() {
session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
query = session.createQuery("from ConfigPersonale");
configPersList = query.list();
session.getTransaction().commit();
return new Vector<ConfigPersonale>(configPersList);
}
}
*********************************************
Please could you help ?
Thanks and best regards,
Luiss
[toc] | [next] | [standalone]
| From | Luiss <luiss@aol.com> |
|---|---|
| Date | 2012-05-07 00:18 +0200 |
| Message-ID | <4fa6f8aa$0$1388$4fafbaef@reader1.news.tin.it> |
| In reply to | #14330 |
Il 06/05/2012 13:09, Stefan Ram ha scritto: > Luiss<luiss@aol.com> writes: >> new DefaultTableModel(dataTable, columnNames) > > « dataTable » dovrebbe essere un vettore di vettori, > non un vettore di ConfigPersonale. > ottimo grazie mille
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-05-06 19:14 -0700 |
| Message-ID | <mubeq7dih60k2kvq94shio4cshupmk8hpk@4ax.com> |
| In reply to | #14330 |
On Sun, 06 May 2012 12:03:46 +0200, Luiss <luiss@aol.com> wrote, quoted or indirectly quoted someone who said : >Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: see http://mindprod.com/jgloss/runerrormessages.html#CLASSCASTEXCEPTION for general information on them. -- Roedy Green Canadian Mind Products http://mindprod.com Programmers love to create simplified replacements for HTML. They forget that the simplest language is the one you already know. They also forget that their simple little markup language will bit by bit become even more convoluted and complicated than HTML because of the unplanned way it grows. .
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-05-06 20:43 -0700 |
| Message-ID | <jo7gdm$pu2$1@news.albasani.net> |
| In reply to | #14330 |
On 05/06/2012 03:03 AM, Luiss wrote:
> Hi all,
>
> I'm writing a GUI to show a JTable cointaining data from a db table (after
> I'll add also buttons to Add, Update and Delete rows). I need to have
> different table fields and not only strings.
>
> I've used Hibernate to do the select and then passed the list to a Vector
> containing ConfigPersonale objects (my table bean).
>
> I get this exception running the GUI:
>
> ********************************
> Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
> com.ale.ts.persistence.ConfigPersonale cannot be cast to java.util.Vector
Don't use 'Vector' anyway, and do perform all GUI work on the Event Dispatch
Thread.
In this code:
> public class QueryConfigPersonale {
> private Session session;
> private Query query;
> private List<ConfigPersonale> configPersList;
>
> //select * from ConfigPersonale
> @SuppressWarnings("unchecked")
> public Vector<ConfigPersonale> getConfigPersonale() {
> session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
> session.beginTransaction();
> query = session.createQuery("from ConfigPersonale");
>
> configPersList = query.list();
> session.getTransaction().commit();
>
> return new Vector<ConfigPersonale>(configPersList);
> }
> }
you use old-fashioned Hibernate ('Session' instead of 'EntityManager'). Use
the JPA style.
Don't suppress unchecked warnings. That's very bad. How do you know it's safe
to do that? You have absolutely no documentation in your code to explain why
it's safe. That's bad.
The Hibernate query returns a list already. Why convert it to a 'Vector'?
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web