NullPointerException

Hi guys, got a problem with the following source that compiles but on run-time I get a nullpointerexception. Do some of you guys have any clue about what could be the cause? Thanks.

import java.io.*;

import java.awt.*;

import java.lang.*;

import java.util.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class Student {

static public BufferedReader keyboard =

new BufferedReader(new InputStreamReader(System.in));

public String name;

public int stnumber; //KEY

public Module modulest[];

/** Creates a new instance of Student */

public Student() {

String name;

int stnumber;

System.out.println("Please input student name: ");

this.name = Text.ReadString(keyboard);

System.out.println("Please input student number: ");

this.stnumber = Text.ReadInt(keyboard);

//students[count]=;

//Module.students[count]=;

}

public String Modules_Taken() {

String result="0";//=" "; // = null;

for(int i=0;i<=1;i++) {

result = result + modulest.modtitle;

}

return result;

}

public String getName() {

return name;

}

public int getStnumber() {

return stnumber;

}

}

import java.io.*;

import java.awt.*;

import java.lang.*;

import java.util.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class TheStuModMain {

static Vector v1,v2;

public static Vector Members = new Vector();

/** Creates a new instance of TheStuModMain */

public TheStuModMain() {

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

v1 = new Vector();

v2 = new Vector();

//Members = new Vector();

Undergraduate undstu = new Undergraduate();

v1.add(undstu);

System.out.println(v1.elementAt(0).toString());

//System.out.println(undstu.Modules_Taken());

//UndModule unmd = new UndModule(8001, "Intro to Comp 1");

//UndModule unmd1 = new UndModule(8003, "Intro to Comp 2"); // Initialisation of the compulsory modules for all undergrads

//Members.add(unmd);

//Members.add(unmd1);

//System.out.println(unmd.modnumber+" " + unmd.title);

//System.out.println(unmd.ToString());// to re-assure these modules have been added 8001 8003 next step to save it in a vector

//v1.addElement(unmd);

//System.out.println(Members.elementAt(0).toString());

//System.out.println(Members.elementAt(1).toString());

// TODO code application logic here

//v1.addElement(unmd);

//v1.elementAt(0);

//System.out.println(v1.get(0));

}

}

Feel Free To Request Any Other .java File

Thanks Again

Here is the ouput msg by netbeans

Exception in thread "main" java.lang.NullPointerException

at Undergraduate.toString(Undergraduate.java:31)

at TheStuModMain.main(TheStuModMain.java:25)

Java Result: 1

BUILD SUCCESSFUL (total time: 10 seconds)

and undegraduate extends student class is here:

import java.io.*;

import java.awt.*;

import java.lang.*;

import java.util.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class Undergraduate extends Student {

//public Vector Members1;

/** Creates a new instance of Undergraduate */

protected int count =2; //2 compulsory modules to be added 8001 8003

protected int count2 = 6; //total number of modules

//protected Module modules[] = new Modules[count];

/*public void AddCompMods() {

for(int i=0;i < Members.size();i++) {

}

}*/

public Undergraduate() {

super();

Module modulest[] = new Module[6];

modulest[0]= new UndModule(8001,"IntroComp");

modulest[1]= new UndModule(8003,"AdvComp");

}

public String toString() {

return ("name: " + getName() + "student number: " +getStnumber() + modulest[0].modtitle ); // Modules_Taken() ); //+ Modules_Taken());

}

//Module modulest[] = new Module[count2];

//for(int i=0;i<count;i++) {

//}

}>

[4319 byte] By [johnsmith12a] at [2007-10-2 14:28:37]
# 1

additional classes:

import java.io.*;

import java.awt.*;

import java.lang.*;

import java.util.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class UndModule extends Module {

/** Creates a new instance of UndModule */

public UndModule(int modnumber,String modtitle) {

super(modnumber, modtitle);

}

public UndModule() {

super();

}

public String toString() {

return ("Undergraduate module number"+ modnumber + "Module name: " + modtitle );

}

}

import java.io.*;

import java.awt.*;

import java.lang.*;

import java.util.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class Module {

static public BufferedReader keyboard =

new BufferedReader(new InputStreamReader(System.in));

protected static final int CAPACITY = 40; // max number of students that can take a module - can be set to whatever is desired within the data type constraint

protected static Student students[] = new Student[CAPACITY];

protected int count = 0;

protected int mark;

protected int modnumber;

protected String modtitle;

//protected boolean isPostgrad; //more undergrad students

/** Creates a new instance of Module */

public Module(int modnumber,String modtitle) {

this.modnumber = modnumber;

this.modtitle = modtitle;

}

public Module() {

System.out.println("Please input module number: ");

this.modnumber=Text.ReadInt(keyboard); // with/out this executed constructor on the main ethod of UndModule gave the same result why?

System.out.println("Please input module title: ");

this.modtitle=Text.ReadString(keyboard);

}

public void enrol(Student s) {

students[count++]=s;

}

public String getModTitle() {

return modtitle;

}

public int getMark() {

return mark;

}

}

johnsmith12a at 2007-7-13 12:49:31 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
SOLVED
johnsmith12a at 2007-7-13 12:49:31 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...