java中一切都是用class来做,定义一个class.按你要求的数据类型做一些东西就是了,
解决方案 »
- 求高人指教,java中关于序列化和反序列化的问题
- 菜鸟问题2
- 关于按钮大小的问题
- 菜鸟问题: 关于字符串中含有"符号
- 从命令行参数得到一整数并判断该数是不是回文数
- 请问java 怎么将一个gif图片画在另一个上 然后存为一个新的gif? 有门路的也可
- 使用预编译PreparedStatment怎么进行事务操作!??
- 怎么调用某种类型文件,让其被默认的应用程序打开
- Exception in thread "main" java.lang.NoClassDefFoundError:Ellsworth(这是我的文件)。上面是我编译通过之后,执行是出现的信息?哪里
- java编译时的问题
- 有搞过个人财务软件的,能不能发个源码
- 如何Java Web Start 部署应用程序
int member1;
int member2;
...
}
int[] array;
}
你在用java写java就是在不停的创建使用自己的数据类型
test[] Mytest;
class test
{
int a;
}
import java.io.*;
public class test
{
int num;
info[] kkk; public static class info
{
int count;
info(){count=0;}
}
public test()
{
int i;
num=0;
for(i=0;i<2;i++)
{
kkk=new info[2];
}
kkk[i].count=1;
kkk[1].count=2;
}
public static void main(String[] args)
{
test p=new test();
System.out.println(p.kkk[1].count);
}
}
main函数中的数组下标是 l 还是 1 ?
for(i=0;i<2;i++)
{
kkk=new info[2];
}
kkk[i].count=1;
你已经定义了数组的大小为2,其中只能有2个元素,最大下标为1,就是说其中元素为info[0]和info[1]循环在i=2时退出,而你又用了 kkk[i].count=1;在此i=2,也就是kkk[2].count,当然会出错
import java.io.*;
public class test
{
int num;
info[] kkk; public static class info
{
int count;
info(){count=0;}
}
public test()
{
int i;
num=0;
kkk=new info[2];
kkk[0].count=1;
kkk[1].count=2;
}
public static void main(String[] args)
{
test p=new test();
System.out.println(p.kkk[1].count);
}
}
运行出错:java.lang.NullPointerException
at test.<init>(test.java:24)
at test.main(test.java:30)
Exception in thread "main"
kkk=new info[2];
kkk[0] = new info();
kkk[0].count=1;
kkk[1] = new info();
kkk[1].count=2;