problem with a program I wrote

1student

Member
May 30, 2004
42
0
0
Hi,

I wrote a problem in Java - quite a long one.
I succeeded to compile it, but when I ran it there were run time exceptions.

Here are the messages I've got:

java.lang.NullPointerException
at SparseMatrix.addStudent(SparseMatrix.java:29)
at SparseMatrix.main(SparseMatrix.java:196)

java.lang.NullPointerException
at SparseMatrix.addCourse(SparseMatrix.java:37)
at SparseMatrix.main(SparseMatrix.java:203)


I would like you to help me find the cause of the problem...

The program I wrote is as follow:
(I indicated the lines Java didn't get).
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Why do you initialize the rows and columns arrays with new Cell objects and then set them to null?

for(int i=0; i<numC; i++)
...{
......rows[ I]=new Cell(i,0);
......rows[ I]=null;
......cols[ I]=new Cell(0,i);
......cols[ I]=null;
...}
 

Yomicron

Golden Member
Mar 5, 2002
1,735
1
81
Originally posted by: 1student
Is it super place?

Also when I delete it, it doesn't work..

Setting the rows and columns to null is only part of the problem. In your Cell class you never initilize Student 's' and Course 'c'.
 

1student

Member
May 30, 2004
42
0
0
I tried to initialize the variables, but it doesn't work yet.
I get that message:
found : SparseMatrix.Course
required: int
c=new Course();
^
1 error

Where is the mistake now?
Here is the program: