-
Returning object arrays
Im having a refrencing problem that i am not too sure how to deal with. When i return an Object array from a method what do i store it in? As an example i have a simple method that when invoked creates a new Object array and adds new instances of other Objects(JButtons) to a JPanel then returns the JButton[] array. When the method returns what to i store the returned refrence in? passDigits(digits) is passing a null Object array. :p
Code:
class X{
JButton[] digits;
JPanel dig = new JPanel();
digits = addDigits(dig);
passDigits(digits);
}
Code:
public JButton[] addDigits(JPanel dig){
JButton[] digits = new JButton[10];
for(int i = 9; i <= 0; --i){
digits[i] = new JButton(String.valueOf(i));
dig.add(digits[i]);
}
return digits;
}
-
I don't see a problem with the code...
-
I found out why i was getting a NullPointerException. The loop never gets executed. When i tried to refrence a element from the JButton[] array thats when the exception is thrown. Sorry my fault. :D
-
Strange.
I was going to tell you to check your condition in the for loop, but the thread was locked. Obviously, the thread is open now.