Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
class cast exception
vijayakumar durai
Ranch Hand
Posts: 153
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i am getting class cast exception can any body tell what is the problem
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author V */ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.sql.*; import java.util.ArrayList; import java.util.Vector; public class ViewEmployee extends JPanel { private boolean DEBUG = false; public ViewEmployee() { super(new GridLayout(1,0)); Vector v1=new Vector(); v1.addElement("Employee Id"); v1.addElement("Name"); v1.addElement("Address"); v1.addElement("Date Of Birth "); v1.addElement("Date Of Joining"); v1.addElement("Designation"); v1.addElement("GrossSalary"); ArrayList list=new ArrayList(); Connection con=null; Statement stmt=null; ResultSet rs=null; int colCount=0; // String[] record=new String[colCount]; Vector v =new Vector(); Vector data=new Vector(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=d:/Project1.mdb;"); stmt=con.createStatement(); rs=stmt.executeQuery("select * from addemp"); ResultSetMetaData meta = rs.getMetaData(); colCount = meta.getColumnCount(); while (rs.next()) { String[] record = new String[colCount]; for (int i = 0; i < colCount; i++) { record[i] = rs.getString(i + 1); } v.addElement(record); } } catch(Exception e) { e.printStackTrace(); } final JTable table = new JTable( v,v1); // getting class cast exception table.setPreferredScrollableViewportSize(new Dimension(500, 70)); //table.setFillsViewportHeight(true); if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //printDebugData(table); } }); } //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); } /* private void printDebugData(JTable table) { int numRows = table.getRowCount(); int numCols = table.getColumnCount(); javax.swing.table.TableModel model = table.getModel(); System.out.println("Value of data: "); for (int i=0; i < numRows; i++) { System.out.print(" row " + i + ":"); for (int j=0; j < numCols; j++) { System.out.print(" " + model.getValueAt(i, j)); } System.out.println(); } System.out.println("--------------------------"); }*/ /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SimpleTableDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. ViewEmployee newContentPane = new ViewEmployee(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Rob Spoor
Sheriff
Posts: 22781
131
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you show us the stack trace?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTable inside JScrollPane - background coloring problem
JRadioButton in JTable
iscelleditable is not working in jtable
JTable is not inserting the data
JScrollPane within JTable cell issue
More...