I have below code.
Complex[] time1Dummy = new Complex[time1.size()];
Complex[] freq1 = new Complex[time1.size()];
System.out.println("Size of time1:" +time1.size());
for(int i = 0; i < time1.size(); i++) {
time1Dummy[i].setRe(time1.get(i));
time1Dummy[i].setIm(0.00);
}
In this, Complex is the class which contains
private static Double re; // the real part
private static Double im; // the imaginary part`
Here, I am trying to assign values from array list time1 to complex value functions.
I am running this code in eclipse 4.3.2. Can someone please help me out in this?
My guess is you are getting null pointer exceptions? See the first line I added within the for loop (assuming Complex has a default constructor).
Complex[] time1Dummy = new Complex[time1.size()];
Complex[] freq1 = new Complex[time1.size()];
System.out.println("Size of time1:" +time1.size());
for(int i = 0; i < time1.size(); i++) {
time1Dummy[i] = new Complex();
time1Dummy[i].setRe(time1.get(i));
time1Dummy[i].setIm(0.00);
}
The first two lines of your code create arrays of Complex objects, but each element does not yet have an object created within it. You need to explicitly create an object first.
Also the attributes should not be static:
private Double re; // the real part
private Double im; // the imaginary part`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With