i know its something simple although ive been having this problem ever since i started using for loops. The program starts when compiling and displays up to the 2nd panel. it seems to stop before the JFormattedTextFields come in. I have been looking and i do have a feeling its to do with my for loop. although if somebody could tell me how to solve this before i tackle the problem myself id still be thankful :D. Also i do know there are similar threads already listed. I had looked at one i tryed a few solutions but had no luck.

The error lines:

Code :

Line 117: panel[0].add(panel[4]);

Code :

Line 65: // Extracted methods
panelSetup();

Code :

Line 48: new frmClient();

Thank you in advance. Also i apologize for the beginner question as i am half a sleep been workin to much this week :D

ye ive just debuged and found its stopping at that line. altho its trying to shove 74 textfields into the first panel of the next for loop. altho it cannot execute any code as that for loop only contains another for loop inside and nothing to make it keep counting i. i guess the real question would be.. what would be the correct syntax to display 7 textfields into the panel then move to the next panel and display another 7 text boxes etc.. would it be seperate for loops i > 7 i > 14 etc...

June 17th, 2011, 09:08 AM

macko

1 Attachment(s)

Re: NullPointerException

wi have 15 panels. stored them in a panel array. 75 JTextFields which are in the txtBox array. the first for loop is suppose todisplay txtBox in the current panel (a) from the second for loop. as ive mentioned above im trying to display 7 txtfields per panel. and the first 3 panels i have already defined the values to put in there which are simply the labels and the company name.

picture below of what the program shuld look like. and inside the black rectangle is what is currently displaying

the above picture is the code i did earlier. although it was 1800 lines of code as i had declared each variable seperate. so ive narrowed it down using for loops to 250 lines and im sort of new to the for loop syntax.

June 17th, 2011, 09:24 AM

william

Re: NullPointerException

I think you have the right idea just backwards.
take the pannel for loop and add 7 text fields as a for loop

so something like this:

Code java:

for(int i =0; i <15; i++){// panel start up codefor(int j =0; j <7; j++){// notice that its less than 7 because i am only using 7 text fields 0-6
textField =newTextField();
jPanel[i].add(textField);}//... more code here}

just an example your using your first for loop to create the panel and the second to fill the panel with text fields.

it seems i was missing a panel which is what displayed null. as for the 7 textfields per panel ill tackle it myself otherwise ill never learn:P

thanks for the help tho uve been helpful pointing out the obvious :)

June 17th, 2011, 09:31 AM

Norm

Re: NullPointerException

Why are you hard coding magic numbers in for loops vs using a final int with a selfdefining name to define the value. This makes for hard to maintain code.
Better would be:
for (int a = StartIndex; a < NbrLeftHandPanels;

June 17th, 2011, 09:36 AM

macko

Re: NullPointerException

only thing i dont understand is how to actualy use the for loop to display 7 text boxes per panel, in the above picture each row is a seperate panel. if i were to use

for(int j = 0 ; j < 7; j++)

would it not keep posting the textfields 1 - 7 through out the whole loop? there are 75 textfields in total. i need to display each of them once not multiple times. or would it be easier to simply use 7 txtfields ? as it will be reading.writng to a file. when reading from the file would it not over write or display the same value multiple times?

June 17th, 2011, 10:59 AM

william

Re: NullPointerException

Quote:

Originally Posted by macko

would it not keep posting the textfields 1 - 7 through out the whole loop? there are 75 textfields in total. i need to display each of them once not multiple times. or would it be easier to simply use 7 txtfields ? as it will be reading.writng to a file. when reading from the file would it not over write or display the same value multiple times?

if each row is a jPanel and each jPanel has 7 text fields in them you have 15 jPanels and only 12 of them have 7 text fields (12 *7 = 84) I would assume that your only going to write to the panels that only need 7 text fields in them.

hope that helps. Best way I test stuff I don't understand is build a simple test program, Look at the results. This case you can use nested loops and display to consoled.
example of what i mean run this code here:

O-o i suppose it is. and its simply making 75 text boxes, once the textbox letter x reaches 45 it will add +1 to the panel. in which it willt hen post the next 7 textboxes onto the next panel etc.. and keep going like that. its so i can recieve data out of a text file and display them in the correct textbox

June 21st, 2011, 11:35 AM

dlorde

Re: NullPointerException

Quote:

Originally Posted by macko

... its simply making 75 text boxes, once the textbox letter x reaches 45 it will add +1 to the panel. in which it willt hen post the next 7 textboxes onto the next panel etc.. and keep going like that.

Sorry, makes no sense at all to me. Closest I can get is: you want 75 text boxes, split between multiple panels with 7 text boxes in each panel - yes?

What does "once the textbox letter x reaches 45 it will add +1 to the panel" mean? How does a letter x reach 45? how can you add +1 to a panel ??