java新手,简单有关问题
阅读
有个类
public class Pair {
int N_Key;
String N_Value;
}
用它定义一个数组,如何初始化呢?
protected Pair [] element;
我这样初始化他:
element[1] = new Pair();
但是用它的时候:
element[1].N_Value,有问题????????
谢谢。
------解决方案--------------------
你的N_Value在用之前没有赋值吧?应该是空指针一场吧?
------解决方案--------------------
先要总体初始化一下:element = new Pair[n];
------解决方案--------------------
int[] a = new int[3];
a[0] = 1; a[1] = 2; a[2] = 3;
int[] a = {1,2,3};
------解决方案--------------------
protected Pair [] chil= new Pair [10];
protected Pair [] chi = {new Pair (),new Pair ()};
要初始化才能用呀,不能直接用
protected Pair [] element;
element[1] = new Pair();
这样是错误的用法
element[1].N_Value
------解决方案--------------------
阅读
上一篇:JDialog 中的 JPanel 镜头设定 下一篇:返回列表