You don't show what code is executed when you press the OK button, so who knows?
One guess is that you have for(z=0;z<=counter;z++)
so if there are 4 entries (ie counter = 4) you are accessing array elements 0-4 inclusive, ie 5 elements, of which the 5th will still be null.
In general, when yo uget a null pointer exception you should print the exception which will tell you teh exact line where it happened. Then you can print the values used on that line to see which is null, then you should be able to work out why.