主题:请高手指教
import java.io.*;
import java.util.*;
class p
{ public int id;
public String name;
public int age;
public String sex;
}
public class kkk
{
public static void main(String[] args)
{
p[] g=new p[1000];
try
{
File file=new File("dd.txt");
BufferedReader in=new BufferedReader(new FileReader(file));
String s;
int i=1;
while((s=in.readLine())!=null)
{
StringTokenizer t=new StringTokenizer(s,",");
g[i].id=Integer.parseInt(t.nextToken());
g[i].name=t.nextToken();
g[i].age=Integer.parseInt(t.nextToken());
g[i].sex=t.nextToken();
i++;
System.out.println(g[i]);
}
in.close();
} catch (Exception e) { e.printStackTrace(); }
}
}
编译能行,可已运行就出错,提示java.lang.NullPointerException,这是怎么回事啊,请教
import java.util.*;
class p
{ public int id;
public String name;
public int age;
public String sex;
}
public class kkk
{
public static void main(String[] args)
{
p[] g=new p[1000];
try
{
File file=new File("dd.txt");
BufferedReader in=new BufferedReader(new FileReader(file));
String s;
int i=1;
while((s=in.readLine())!=null)
{
StringTokenizer t=new StringTokenizer(s,",");
g[i].id=Integer.parseInt(t.nextToken());
g[i].name=t.nextToken();
g[i].age=Integer.parseInt(t.nextToken());
g[i].sex=t.nextToken();
i++;
System.out.println(g[i]);
}
in.close();
} catch (Exception e) { e.printStackTrace(); }
}
}
编译能行,可已运行就出错,提示java.lang.NullPointerException,这是怎么回事啊,请教