pointers - Java JList - Argument must not be null -
i have problem compiling java program. have no idea why error when create new object in line 103... error is:
exception in thread "main" java.lang.nullpointerexception: argument must not null @ javax.swing.spring.checkarg(spring.java:688) @ javax.swing.spring.width(spring.java:657) @ javax.swing.springlayout.applydefaults(springlayout.java:1093) @ javax.swing.springlayout.putconstraints(springlayout.java:1123) @ javax.swing.springlayout.getconstraints(springlayout.java:1158) @ javax.swing.springlayout.putconstraint(springlayout.java:1080) @ javax.swing.springlayout.putconstraint(springlayout.java:1075) @ javax.swing.springlayout.putconstraint(springlayout.java:1041) @ cwiczenie9.cwiczenie9.setspringlayoutconstraint(cwiczenie9.java:204) @ cwiczenie9.cwiczenie9.<init>(cwiczenie9.java:31) @ cwiczenie9.cwiczenie9.main(cwiczenie9.java:232) java result: 1 build successful (total time: 2 seconds)
my application code here:
package cwiczenie9; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class cwiczenie9 extends jframe { private container container; private springlayout sprlay; private jlabel[] jlabel; private jtextfield[] jtextfield; private jradiobutton[] jradiobutton; private buttongroup buttongroup; private spinnermodel spinnermodel; private jspinner jspinner; private jbutton[] jbutton; private jlist jlist; private final string[] jlistitems = {"pies", "kot", "chomik", "królik", "jaszczurka", "pająk", "rybki", "owady"}; public cwiczenie9() { addcontainer(); setframeproperties(); createjlabel(5); createjtextfield(2); createjradiobutton(2); createjspinner(0, 0, 99, 1); createjbutton(2); setspringlayoutconstraint(); } private void addcontainer() { sprlay = new springlayout(); container = this.getcontentpane(); container.setlayout(sprlay); } private void setframeproperties() { this.settitle("ankieta"); this.setsize(300, 300); this.setlocation(150, 150); this.setdefaultcloseoperation(jframe.exit_on_close); } private void createjlabel(int count) { jlabel = new jlabel[count]; for(int = 0; < count; i++) jlabel[i] = new jlabel(); jlabel[0].settext("imię:"); jlabel[1].settext("nazwisko:"); jlabel[2].settext("płeć:"); jlabel[3].settext("wiek:"); jlabel[4].settext("wybierz zwierzęta, które posiadasz w domu:"); for(jlabel jl : jlabel) container.add(jl); } private void createjtextfield(int count) { jtextfield = new jtextfield[count]; for(int = 0; < count; i++) jtextfield[i] = new jtextfield(); jtextfield[0].setcolumns(15); jtextfield[1].setcolumns(15); for(jtextfield jtf : jtextfield) container.add(jtf); } private void createjradiobutton(int count) { jradiobutton = new jradiobutton[count]; buttongroup = new buttongroup(); for(int = 0; < count; i++) jradiobutton[i] = new jradiobutton(); jradiobutton[0].settext("kobieta"); jradiobutton[1].settext("mężczyzna"); for(jradiobutton jrb : jradiobutton) { buttongroup.add(jrb); container.add(jrb); } } private void createjspinner(int initialvalue, int minvalue, int maxvalue, int step) { spinnermodel = new spinnernumbermodel(initialvalue, minvalue, maxvalue, step); jspinner = new jspinner(spinnermodel); container.add(jspinner); } private void createjbutton(int count) { jbutton = new jbutton[count]; for(int = 0; < count; i++) jbutton[i] = new jbutton(); jbutton[0].settext("zatwierdź"); jbutton[1].settext("anuluj"); for(jbutton jb : jbutton) container.add(jb); } private void createjlist() { jlist = new jlist(jlistitems); jlist.setpreferredsize(new dimension(120, 80)); jlist.setselectionmode(listselectionmodel.single_selection); jlist.setlayoutorientation(jlist.vertical_wrap); jlist.setvisiblerowcount(5); container.add(jlist); } private void setspringlayoutconstraint() { // jlabel[0] - north <-> north sprlay.putconstraint(springlayout.north, jlabel[0], 10, springlayout.north, container); // jlabel[0] - west <--> west sprlay.putconstraint(springlayout.west, jlabel[0], 10, springlayout.west, container); // jtextfield[0] - north <-> north sprlay.putconstraint(springlayout.north, jtextfield[0], 10, springlayout.north, container); // jtextfield[0] - west <-> east sprlay.putconstraint(springlayout.west, jtextfield[0], 10, springlayout.east, jlabel[0]); // jlabel[1] - north <-> south sprlay.putconstraint(springlayout.north, jlabel[1], 15, springlayout.south, jlabel[0]); // jlabel[1] - west <--> west sprlay.putconstraint(springlayout.west, jlabel[1], 10, springlayout.west, container); // jtextfield[1] - north <-> south sprlay.putconstraint(springlayout.north, jtextfield[1], 15, springlayout.south, jtextfield[0]); // jtextfield[1] - west <-> east sprlay.putconstraint(springlayout.west, jtextfield[1], 10, springlayout.east, jlabel[1]); // jlabel[2] - north <-> south sprlay.putconstraint(springlayout.north, jlabel[2], 15, springlayout.south, jlabel[1]); // jlabel[2] - west <--> east sprlay.putconstraint(springlayout.west, jlabel[2], 10, springlayout.west, container); // jradiobutton[0] - north <-> south sprlay.putconstraint(springlayout.north, jradiobutton[0], 15, springlayout.south, jtextfield[1]); // jradiobutton[0] - west <-> east sprlay.putconstraint(springlayout.west, jradiobutton[0], 10, springlayout.east, jlabel[2]); // jradiobutton[1] - north <-> south sprlay.putconstraint(springlayout.north, jradiobutton[1], 15, springlayout.south, jtextfield[1]); // jradiobutton[1] - west <-> east sprlay.putconstraint(springlayout.west, jradiobutton[1], 10, springlayout.east, jradiobutton[0]); // jlabel[3] - north <-> south sprlay.putconstraint(springlayout.north, jlabel[3], 15, springlayout.south, jlabel[2]); // jlabel[3] - west <-> west sprlay.putconstraint(springlayout.west, jlabel[3], 10, springlayout.west, container); // jspinner - north <-> south sprlay.putconstraint(springlayout.north, jspinner, 15, springlayout.south, jradiobutton[0]); // jspinner - west <-> east sprlay.putconstraint(springlayout.west, jspinner, 10, springlayout.east, jlabel[3]); // jlabel[4] - north <-> south sprlay.putconstraint(springlayout.north, jlabel[4], 15, springlayout.south, jlabel[3]); // jlabel[4] - west <-> west sprlay.putconstraint(springlayout.west, jlabel[4], 10, springlayout.west, container); // jlist - north <-> south sprlay.putconstraint(springlayout.north, jlist, 15, springlayout.south, jlabel[4]); // jlist - west <-> west sprlay.putconstraint(springlayout.west, jlist, 10, springlayout.west, container); // jbutton[0] - north <-> south sprlay.putconstraint(springlayout.north, jbutton[0], 15, springlayout.south, jlist); // jbutton[0] - west <-> west sprlay.putconstraint(springlayout.west, jbutton[0], 10, springlayout.west, container); // jbutton[1] - north <-> south sprlay.putconstraint(springlayout.north, jbutton[1], 15, springlayout.south, jlist); // jbutton[1] - west <-> east sprlay.putconstraint(springlayout.west, jbutton[1], 10, springlayout.east, jbutton[0]); } public static void main(string[] args) { cwiczenie9 cw9 = new cwiczenie9(); cw9.setvisible(true); } }
thank in advance :)
you trying access object, appears null
in method setspringlayoutconstraint()
on line 204. more information required answer question.
show code method setspringlayoutconstraint()
, , number lines more dtailed answer.
Comments
Post a Comment