Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type has not been loaded occurred while retrieving component type of array error occurred

Tags:

java

eclipse

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?

like image 595
Dinesh Avatar asked Jul 21 '14 00:07

Dinesh


1 Answers

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`
like image 91
Khary Mendez Avatar answered Nov 04 '22 19:11

Khary Mendez