RecordType [] r=new RecordType[10];是数组对象,你不能直接给其某个元素中的属性赋值,要先实例化数组中的某个元素。
public class Sqlist {
static class RecordType{
int key;
int otherwise;
}
RecordType [] r=new RecordType[10];
int length=1;
}
public class Test{
public static void main(String[] args) {
Sqlist arr=new Sqlist();
Sqlist.RecordType r=new Sqlist.RecordType();
r.key=1;
r.otherwise=2;
arr.r[1]=r;
System.out.println(arr.r[1].key);
}
}
你arr.r[1] 是 null
你检查下你arr.r的值是数组吗?