aspose file tools*
The moose likes JDBC and the fly likes exception while creating JTables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

exception while creating JTables

Karan Raj
Greenhorn

Joined: Jan 27, 2004
Posts: 16
hi,
I am getting the following exception with my program.please chek this once.
Exception in thread "main" java.lang.ClassCastException
at javax.swing.table.DefaultTableModel.justifyRows DefaultTableModel.jav
a:238)
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
ava:194)
at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:131
)
at guidemo.<init>(guidemo.java:37)
at guidemo.main(guidemo.java:60)
----------------------------------------------------------------
i am tried to create a table with vectors.my code is as follows
code:-
-----
class guidemo extends JFrame{
private JTable data_tab;
private JLabel ptitle;
private Container c;
private Vector vdata;
private Vector vcolname;

public guidemo(){
super("EST Project Demo");
DefaultTableModel dtm;

c=getContentPane();
c.setLayout(null);
c.setSize(300,200);//intialising the contentpane



ptitle=new JLabel("EST project Details");

ptitle.setBounds(60,30,150,40);

c.add(ptitle);
setTableData();//intialising the vectors with some data

dtm=new DefaultTableModel(vdata,vcolname);
data_tab=new JTable(dtm);//setting table model
//data_tab.setPreferredScrollableViewportSize(new Dimension(500, 100));
c.add(data_tab);

WindowListener wndCloser = new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};

addWindowListener(wndCloser);
setVisible(true);

}

public static void main(String[] args)
{
System.out.println("Hello World!");
setDefaultLookAndFeelDecorated(true);
new guidemo();
}

public void setTableData(){//intialise vectors with some data
vdata=new Vector();
vcolname=new Vector();
vdata.removeAllElements();
vdata.addElement(new dat("Eliuh",90,900,"uy89"));
vdata.addElement(new dat("Eryuh",920,900,"uy89"));
vdata.addElement(new dat("Elddh",940,900,"uy89"));
vdata.addElement(new dat("Elideu",90,900,"uy89"));
vdata.addElement(new dat("Elwciuh",760,900,"uy89"));
vdata.addElement(new dat("Elhhiuh",90,900,"uy89"));
vdata.addElement(new dat("Elicuh",100,900,"uy89"));
vdata.addElement(new dat("Eliuech",90,900,"uy89"));
vcolname.addElement(new cname("NAME","QStart","Qend","PID"));
}

}

class dat{
String name,gid;
int val,val2;
public dat(String n,int v,int v1,String g){
name=n;
val=v;
val2=v1;
gid=g;

}
}
class cname{
String s1,s2,s3,s4;
cname(String q, String w, String t, String y){
s1=q;
s2=w;
s3=t;
s4=y;
}
}
----------------------------------------------------------
I am not able to understand why i am getting that exception.if any body have solution for my problem it will be greatly helpful for me.
thanks,
karan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61755
    
  67

Closing since you already asked this in the Swing forum. Please do not cross-post the same question in multiple forums.
bear
JDBC Forum Bartender
[ March 19, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception while creating JTables