Java. Lang. nullpointerexception error reported for getcolumnclass () of swing jtable

Source: Internet
Author: User

The function to be implemented is to add check boxes to the table. You need to override the getcolumnclass () method of jtable. jtable supports check boxes by default, make sure that the values of the columns to be displayed as check boxes are Boolean and editable and the columns to be added are editable, it is generally implemented by rewriting the iscelleditable method of the data model corresponding to the jtable.

 

The error code is as follows:

Private jtable gettable () {<br/> If (Table = NULL) {<br/> table = new jtable () {<br/> Private Static final long serialversionuid = 1l; <br/> public class getcolumnclass (INT c) {<br/> return getvalueat (0, c ). getclass (); // error <br/>}< br/>}; </P> <p> table. setmodel (this. gettmtablehba (); <br/> table. setselectionmode (listselectionmodel. single_selection); // sets the selection mode (single choice) <br/> table. gettableheader (). setreorderingallowed (true); // allow sorting <br/> table. gettableheader (). setresizingallowed (true); // you can drag to change the column width. <br/>}< br/> return table; <br/>}

The error message is as follows:

Exception in thread "AWT-EventQueue-1" Java. lang. nullpointerexception <br/> at com. inspur. webManager. gui. server. panel. createhbapanel $1. getcolumnclass (createhbapanel. java: 206) <br/> at javax. swing. jtable. getcellrenderer (unknown source) <br/> at javax. swing. plaf. basic. basictableui. paintcell (unknown source) <br/> at javax. swing. plaf. basic. basictableui. paintcells (unknown source) <br/> at javax. swing. plaf. basic. basictableui. paint (unknown source) <br/> at javax. swing. plaf. componentui. update (unknown source) <br/> at javax. swing. jcomponent. paintcomponent (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jviewport. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. paintchildren (unknown source) <br/> at javax. swing. jcomponent. paint (unknown source) <br/> at javax. swing. jcomponent. painttooffscreen (unknown source) <br/> at javax. swing. bufferstrategypaintmanager. paint (unknown source) <br/> at javax. swing. repaintmanager. paint (unknown source) <br/> at javax. swing. jcomponent. _ paintimmediately (unknown source) <br/> at javax. swing. jcomponent. paintimmediately (unknown source) <br/> at javax. swing. repaintmanager. paintdirtyregions (unknown source) <br/> at javax. swing. repaintmanager. paintdirtyregions (unknown source) <br/> at javax. swing. repaintmanager. seqpaintdirtyregions (unknown source) <br/> at javax. swing. systemeventqueueutilities $ componentworkrequest. run (unknown source) <br/> at java. AWT. event. invocationevent. dispatch (unknown source) <br/> at java. AWT. eventqueue. dispatchevent (unknown source) <br/> at java. AWT. eventdispatchthread. pumponeeventforfilters (unknown source) <br/> at java. AWT. eventdispatchthread. pumpeventsforfilter (unknown source) <br/> at java. AWT. eventdispatchthread. pumpeventsforhierarchy (unknown source) <br/> at java. AWT. eventdispatchthread. pumpevents (unknown source) <br/> at java. AWT. eventdispatchthread. pumpevents (unknown source) <br/> at java. AWT. eventdispatchthread. run (unknown source) <br/>

 

The following error is returned:

Private void initpaneldata (server) {<br/> object [] devicerowdata = new object [] {Boolean. true, "A", "B", "C", "D", "E", "F"}; // error <br/> This. gettmtablehba (). addrow (devicerowdata); <br/>}

First, the columns corresponding to the check box must be of the boolean type, and then the data must be filled in full and cannot be omitted. Even if the corresponding column does not have a value, it must be expressed with a null character.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.