Test class returning null
Hi, I'm a beginner programmer so apologies if this seems like a stupid question!
I've tried to initialize my field numbers with an array of numbers in a constructor in one class and then call it in my test class and display it as a string but it keeps returning null....any help would be appreciated!
This is my class that has the constructor
Code:
public class NumerbList implements Number {
ArrayList<Number> numbers = new ArrayList<Number>();
//constructor taking array of type double as parameter
public NumberList(Double[] numberlist){
for(int i=0; i<numberlist.length; i++){
NumberDouble numberd = new NumberDouble(numberlist[i]);
numbers.add(numberd);
}
}
and this is the class that tests it
Code:
public class Test {
public static void main(String[]args){
Double[] d = {2.4, 3.6, 4.3, 5.1};
NumberList numbers = new NumberList(d);
numbers.neg();
System.out.print(numbers.asString());
}
}
Re: Test class returning null
Does the code you posted compile OK? If there are errors, copy the full text and paste it there.