class KeChengItem
{
public int int_item;
public String str_item;
public KeChengItem()
{
int_item=0;
str_item="1";
System.out.println(str_item);
}
}
class KeCheng
{
public KeChengItem[] kcitem=new KeChengItem[7];
public KeCheng()
{
for(int i=0;i<=6;i++)
System.out.println(kcitem[i].str_item);
}
}
class test {
public static void main(String [] args)
{
KeChengItem kcitem=new KeChengItem();
KeCheng kc =new KeCheng();
}
}这段代码为什么有通不过编译啊,下面是错误提示:
Exception in thread "main" java.lang.NullPointerException
at KeCheng.<init>(test.java:18)
at test.main(test.java:25)
{
public int int_item;
public String str_item;
public KeChengItem()
{
int_item=0;
str_item="1";
System.out.println(str_item);
}
}
class KeCheng
{
public KeChengItem[] kcitem=new KeChengItem[7];
public KeCheng()
{
for(int i=0;i<=6;i++)
System.out.println(kcitem[i].str_item);
}
}
class test {
public static void main(String [] args)
{
KeChengItem kcitem=new KeChengItem();
KeCheng kc =new KeCheng();
}
}这段代码为什么有通不过编译啊,下面是错误提示:
Exception in thread "main" java.lang.NullPointerException
at KeCheng.<init>(test.java:18)
at test.main(test.java:25)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货