Java 检索组件类型时发生类型未加载数组错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24856190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Type has not been loaded occurred while retrieving component type of array error occurred
提问by Dinesh
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
在这里, Complex 是包含
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.
在这里,我试图将数组列表 time1 中的值分配给复数值函数。
I am running this code in eclipse 4.3.2. Can someone please help me out in this?
我在 eclipse 4.3.2 中运行此代码。有人可以帮我解决这个问题吗?
采纳答案by Khary Mendez
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).
我的猜测是您收到空指针异常?请参阅我在 for 循环中添加的第一行(假设 Complex 具有默认构造函数)。
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.
代码的前两行创建了 Complex 对象的数组,但每个元素还没有在其中创建对象。您需要先显式创建一个对象。
Also the attributes should not be static:
此外,属性不应是静态的:
private Double re; // the real part
private Double im; // the imaginary part`