not clear with the basics of nullpont error; trying to create student database
import java.io.*;
class student1
{
String name;
int id;
public void getdata(String name1,int id1)
{
name=name1;
id=id1;
}
public void putdata()
{
System.out.println("\t"+id+" "+name);
}
}
class student
{
public static void main(String args[])throws IOException
{
BufferedReader br= new BufferedReader(new
InputStreamReader(System.in));
BufferedReader br1= new BufferedReader(new
InputStreamReader(System.in));
student1[] n=new student1[10];
for(int i=0;i<5;i++)
{
n[i].getdata(br.readLine(),Integer.parseInt(br1.readLine()));
n[i].putdata();
}
}
}
akulkarni
0
Junior Poster
Recommended Answers
Jump to PostThe exception contains a line number, so which line is it?
Jump to PostAnd which line there is line 29?
Jump to Postn[] is new array, has nothing in it. So n has nothing in it for all values of i, so n.someFunction tries to call someFunction on a null value -> Exception.
Maybe initialise n to new Student1() before using it?
All 11 Replies
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
akulkarni
0
Junior Poster
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
akulkarni
0
Junior Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
akulkarni
commented:
excellent for a newbie like me
+1
akulkarni
0
Junior Poster
akulkarni
0
Junior Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
akulkarni
0
Junior Poster
akulkarni
0
Junior Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.