Null pointer exception

I have written a program which reads file into a binary search tree.

I used string tokenizer to split the text into stringpart and int part.

I gives me null pointer exception.

Can anyone help me so the the file will red inorder binary search tree.

class CityNode

{

String name;

int temperature;

protected CityNode left;// left node

protected String d;// data item

protected CityNode right; // right node.

CityNode(String d) // Constructor

{

d = null;

left = right = null;

}

}

public class City

{

private String name;

private int temperature;

// The root node of the tree initialised here to null

public CityNoderoot;

//public City(String nameIn, int temperatureIn)

//{ }

private CityNode insert(String d, int temp)

{

name = d;

temperature = temp;

root = null;

// insert a node into tree

// void insert(String d)

CityNode current = root;

CityNode prev = current;

if(root == null) {

root = new CityNode(d);

}

else{

boolean insert = false;

while(insert == false){

prev = current;

if (d.compareTo(current.d)<0) {

if (current.left == null){

current.left = new CityNode(d);

insert = true;

}

current = current.left;

}

else{

if (current.right == null){

current.right = new CityNode(d);

insert = true;

}

current =current.right;

}

}

}

return root;

}

// public String getName() { return name; }

// Return a student's age

// public int getTemperature() { return temperature; }

//in order

CityNode inord(CityNode tree) {

int t = 0;

CityNode ret;

CityNode prev;

// prev = new CityNode();

prev = tree;

tree = tree.right;

while (tree.left != null) {

prev = tree;

tree = tree.left;

t = 1;

}

ret = tree;

if (t == 0) {

prev.right = null;

}

else {

prev.left = null;

}

tree = null;

return ret;

}

//print the node

public void printIn(CityNode oot) {

if (oot.left != null) {

printIn(oot.left);

}

System.out.println("--" + oot.d + "-");

if (oot.right != null) {

printIn(oot.right);

}

}

}

import java.util.*;

import java.io.*;

public class CityTest

{

static BufferedReader fileInput;

public static void main( String args[ ] )throws IOException

{

String inputString;

String name;

int temperature, i =0;

StringTokenizer tokens;

// I assmume only 4 students as was indicated in the tutorial

City [] sArray = new City[30];

fileInput = new BufferedReader( new FileReader("Citys.dat"));

inputString = fileInput.readLine();

// read the file until null is returned

while(inputString != null)

{

// First you need to split the string using the String Tokenizer

tokens = new StringTokenizer(inputString);

name = tokens.nextToken(); // I have extracted the first component

temperature = Integer.parseInt(tokens.nextToken());

City tree = new City();

System.out.println ( "\n\nInorder " );

//tree.inord();

tree.printIn(tree.root);

}

}

}

[3474 byte] By [Ricadoa] at [2007-10-3 11:32:08]
# 1

1. I will NOT read your code.

2. Post the stack trace of the error it gives you, that will help pin-point what is wrong and where it is.

a NullPointerException is thrown when a reference is made to a null (non-initialized) object. This means that it has not yet been created or has been collected out of memory.

watertownjordana at 2007-7-15 13:58:56 > top of Java-index,Java Essentials,Java Programming...
# 2
When you post code, use [code] [/code] tags so that it's legible.When you post exceptions, post the entire stack trace rather than just the name of the exception, and indicate the relevant line numbers in the code.
YAT_Archivista at 2007-7-15 13:58:56 > top of Java-index,Java Essentials,Java Programming...
# 3
pls post ur error
daveknirava at 2007-7-15 13:58:56 > top of Java-index,Java Essentials,Java Programming...