Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-11-2004, 10:27 PM   PM User | #1
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
Java nullPointerExeption

Code:
import TerminalIO.KeyboardReader;

public class manyStudents {
	public static void main (String [] args) {
		KeyboardReader 	reader 	= new KeyboardReader();
		Student[] 		student = new Student[500];
		int 			stuNumb = reader.readInt ("Enter the number of students (max is 500): ");
		
		for (int i = 0; i < stuNumb; i++) {
			String stuName = reader.readLine ("Enter the name of sutden #"+ (i+1) +": ");
			student[i].setName(stuName);
			int testNumb = reader.readInt ("Enter the number of tests for "+ student[i].getName() +": ");
		}
	}
}
this code gives me a null pointer exeption at line 11...

why? how can i fix it?

thanks
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Old 06-12-2004, 12:34 AM   PM User | #2
Celtboy
Regular Coder

 
Join Date: May 2002
Location: Virginia, USA
Posts: 620
Thanks: 0
Thanked 6 Times in 6 Posts
Celtboy is an unknown quantity at this point
in line 11, you try to access student[i] ... but student is an object, not an array.

What does your Student class look like?
Celtboy is offline   Reply With Quote
Old 06-12-2004, 12:37 AM   PM User | #3
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
from the code it looks like it would be an array of strings where each element in the array is a students name and the array is 500 names long...


Jason
Jason is offline   Reply With Quote
Old 06-12-2004, 01:18 AM   PM User | #4
Celtboy
Regular Coder

 
Join Date: May 2002
Location: Virginia, USA
Posts: 620
Thanks: 0
Thanked 6 Times in 6 Posts
Celtboy is an unknown quantity at this point
that may be the intent, but it isn't the code. He'd need:

Code:
String[] student = new String[500];
Celtboy is offline   Reply With Quote
Old 06-12-2004, 05:23 PM   PM User | #5
JAVAEOC
Regular Coder

 
Join Date: Oct 2003
Location: SC
Posts: 936
Thanks: 0
Thanked 0 Times in 0 Posts
JAVAEOC is an unknown quantity at this point
i found it, thanks guys


Code:
student[i] = new Student();
thats all i forgot to do :P

thanks
__________________
http://www.bluephoenix.uni.cc/
JAVAEOC is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.