java - I'm getting a cannot format given object as number exception when I run this code. Not sure what's wrong -



java - I'm getting a cannot format given object as number exception when I run this code. Not sure what's wrong -

i'm new java , running code display contents of 1 table in database(logs). function getdata converts resultset 2d string array , returns it. funtion working fine other queries. in database timestamp of time stamp type. creating problem?

package stock; public class viewtrans extends javax.swing.jframe { public viewtrans() { initcomponents(); login l=new login(); string uname=l.getusername(); dbconnect db=new dbconnect(); string str[][]=db.getdata("select sname,amount,value,timestamp,operation,brokerage logs username='"+uname+"'"); for(int i=0;i<10;i++) { for(int j=0;j<5;j++) { ltable.setvalueat(str[i][j],i,j); } } } @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jscrollpane1 = new javax.swing.jscrollpane(); ltable = new javax.swing.jtable(); homebutton = new javax.swing.jbutton(); viewaccbutton = new javax.swing.jbutton(); viewcurrstockbutton = new javax.swing.jbutton(); ebutton = new javax.swing.jbutton(); jlabel1 = new javax.swing.jlabel(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); ltable.setmodel(new javax.swing.table.defaulttablemodel( new object [][] { {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null} }, new string [] { "company name", "no of shares", "value of share", "timestamp", "operation", "brokerage" } ) { class[] types = new class [] { java.lang.string.class, java.lang.integer.class, java.lang.double.class, java.lang.object.class, java.lang.string.class, java.lang.double.class }; public class getcolumnclass(int columnindex) { homecoming types [columnindex]; } }); jscrollpane1.setviewportview(ltable); homebutton.settext("home"); homebutton.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { homebuttonactionperformed(evt); } }); viewaccbutton.settext("view account"); viewaccbutton.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { viewaccbuttonactionperformed(evt); } }); viewcurrstockbutton.settext("view current stock"); viewcurrstockbutton.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { viewcurrstockbuttonactionperformed(evt); } }); ebutton.settext("exit"); ebutton.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { ebuttonactionperformed(evt); } }); jlabel1.settext("your transactions:"); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(20, 20, 20) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jlabel1) .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 497, javax.swing.grouplayout.preferred_size))) .addgroup(layout.createsequentialgroup() .addgap(49, 49, 49) .addcomponent(homebutton) .addgap(36, 36, 36) .addcomponent(viewaccbutton) .addgap(28, 28, 28) .addcomponent(viewcurrstockbutton) .addgap(33, 33, 33) .addcomponent(ebutton)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap(13, short.max_value) .addcomponent(jlabel1) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 191, javax.swing.grouplayout.preferred_size) .addgap(45, 45, 45) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(viewaccbutton) .addcomponent(viewcurrstockbutton) .addcomponent(homebutton) .addcomponent(ebutton)) .addgap(82, 82, 82)) ); pack(); }// </editor-fold> private void homebuttonactionperformed(java.awt.event.actionevent evt) { homepage h=new homepage(); h.setvisible(true); dispose(); } private void ebuttonactionperformed(java.awt.event.actionevent evt) { dispose(); } private void viewcurrstockbuttonactionperformed(java.awt.event.actionevent evt) { viewstock vs=new viewstock(); vs.setvisible(true); dispose(); } private void viewaccbuttonactionperformed(java.awt.event.actionevent evt) { viewaccount h=new viewaccount(); h.setvisible(true); dispose(); } public static void main(string args[]) { java.awt.eventqueue.invokelater(new runnable() { public void run() { new viewtrans().setvisible(true); } }); } // variables declaration - not modify private javax.swing.jbutton ebutton; private javax.swing.jbutton homebutton; private javax.swing.jlabel jlabel1; private javax.swing.jscrollpane jscrollpane1; private javax.swing.jtable ltable; private javax.swing.jbutton viewaccbutton; private javax.swing.jbutton viewcurrstockbutton; // end of variables declaration }

i next error:

exception in thread "awt-eventqueue-0" java.lang.illegalargumentexception: cannot format given object number @ java.text.decimalformat.format(decimalformat.java:505) @ java.text.format.format(format.java:157) @ javax.swing.plaf.synth.synthtableui$synthtablecellrenderer.configurevalue(synthtableui.java:803) @ javax.swing.plaf.synth.synthtableui$synthtablecellrenderer.gettablecellrenderercomponent(synthtableui.java:790) @ javax.swing.jtable.preparerenderer(jtable.java:5736) @ javax.swing.plaf.synth.synthtableui.paintcell(synthtableui.java:684) @ javax.swing.plaf.synth.synthtableui.paintcells(synthtableui.java:581) @ javax.swing.plaf.synth.synthtableui.paint(synthtableui.java:365) @ javax.swing.plaf.synth.synthtableui.update(synthtableui.java:276) @ javax.swing.jcomponent.paintcomponent(jcomponent.java:778) @ javax.swing.jcomponent.paint(jcomponent.java:1054) @ javax.swing.jcomponent.paintchildren(jcomponent.java:887) @ javax.swing.jcomponent.paint(jcomponent.java:1063) @ javax.swing.jviewport.paint(jviewport.java:731) @ javax.swing.jcomponent.paintchildren(jcomponent.java:887) @ javax.swing.jcomponent.paint(jcomponent.java:1063) @ javax.swing.jcomponent.paintchildren(jcomponent.java:887) @ javax.swing.jcomponent.paint(jcomponent.java:1063) @ javax.swing.jcomponent.paintchildren(jcomponent.java:887) @ javax.swing.jcomponent.paint(jcomponent.java:1063) @ javax.swing.jlayeredpane.paint(jlayeredpane.java:585) @ javax.swing.jcomponent.paintchildren(jcomponent.java:887) @ javax.swing.jcomponent.painttooffscreen(jcomponent.java:5226) @ javax.swing.repaintmanager$paintmanager.paintdoublebuffered(repaintmanager.java:1529) @ javax.swing.repaintmanager$paintmanager.paint(repaintmanager.java:1452) @ javax.swing.repaintmanager.paint(repaintmanager.java:1249) @ javax.swing.jcomponent.paint(jcomponent.java:1040) @ java.awt.graphicscallback$paintcallback.run(graphicscallback.java:39) @ sun.awt.sungraphicscallback.runonecomponent(sungraphicscallback.java:78) @ sun.awt.sungraphicscallback.runcomponents(sungraphicscallback.java:115) @ java.awt.container.paint(container.java:1967) @ java.awt.window.paint(window.java:3877) @ javax.swing.repaintmanager$3.run(repaintmanager.java:819) @ javax.swing.repaintmanager$3.run(repaintmanager.java:796) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ javax.swing.repaintmanager.paintdirtyregions(repaintmanager.java:796) @ javax.swing.repaintmanager.paintdirtyregions(repaintmanager.java:769) @ javax.swing.repaintmanager.prepaintdirtyregions(repaintmanager.java:718) @ javax.swing.repaintmanager.access$1100(repaintmanager.java:62) @ javax.swing.repaintmanager$processingrunnable.run(repaintmanager.java:1677) @ java.awt.event.invocationevent.dispatch(invocationevent.java:312) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:733) @ java.awt.eventqueue.access$200(eventqueue.java:103) @ java.awt.eventqueue$3.run(eventqueue.java:694) @ java.awt.eventqueue$3.run(eventqueue.java:692) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ java.awt.eventqueue.dispatchevent(eventqueue.java:703) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91)

it's quite simple. you're telling swing table columns contain, respectively, string, integer, double, etc.:

public class getcolumnclass(int columnindex) { homecoming types [columnindex]; }

but that's not case, since here's how you're populating table model:

string str[][]=db.getdata("select sname,amount,value,timestamp,operation,brokerage logs username='"+uname+"'"); for(int i=0;i<10;i++) { for(int j=0;j<5;j++) { ltable.setvalueat(str[i][j],i,j); } }

so every cell contains string.

java sql arrays swing jtable

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -