Results 1 to 1 of 1
Thread: Null pointer exceptio
- 03-05-2010, 02:00 AM #1
Member
- Join Date
- Jul 2009
- Location
- I live in Jacksonville, Fl
- Posts
- 4
- Rep Power
- 0
Null pointer exceptio
So when I run my code I get a null pointer exception, I can't figure out why, I thought I had covered myself on this problem. Any help will be greatly appreciated. The error happen in the second printCode method at the if statement.
There is obviously more code I just took out stuff that was in no way related to my problem, but if you think you need some missing code to help me I can gladly post it.Java Code:import java.io.*; import java.util.Scanner; public class data5 { public static void main(String[] args)throws Exception{ Huffman encode=new Huffman(args[0]); encode.printCode(); } } class node{ private int freq; private char stuff='\0'; private node leftChild=null; private node rightChild=null; public node(int newData){ freq=newData; } public node(int newData, char newStuff){ freq=newData; stuff=newStuff; } public void makeLeft(int newData){ node temp=new node(newData); this.leftChild=temp; } public void makeLeft(node temp){ this.leftChild=temp; } public void makeRight(node temp){ this.rightChild=temp; } public void makeRight(int newData){ node temp=new node(newData); this.rightChild=temp; } public node getLeft(){ return leftChild; } public node getRight(){ return rightChild; } public int getData(){ return freq; } public char getChar(){ return stuff; } } class tree{ private node root=null; private treeIterator monkey; public tree(){ } public tree(int data){ root=new node(data); } public tree(int data, char letter){ root=new node(data, letter); } public void addNode(int data){ if(root==null) root=new node(data); else{ monkey=new treeIterator(root); while(monkey.current!=null){ if(data<monkey.current.getData()) monkey.goLeft(); else monkey.goRight(); } if(data<monkey.current.getData()) monkey.previous.makeLeft(data); else monkey.previous.makeRight(data); } } public node getNode(){ return root; } public int compare(tree test){ int difference; difference=this.root.getData()-test.getNode().getData(); return difference; } } class Huffman { private tree encodedInfo; private File source; private Scanner input; private char[] letters; private int[] frequency=new int[9]; private PriorityQueue setup; public Huffman(String fileName)throws Exception { } private void getFrequency(){ } } private tree makeTree(){ tree temp=null; int howMany=9; while(howMany>2){ temp=new tree(setup.getInfo(0).getNode().getData()+setup.getInfo(1).getNode().getData()); temp.getNode().makeLeft(setup.getInfo(0).getNode()); temp.getNode().makeLeft(setup.getInfo(1).getNode()); setup.setValue(0,temp); setup.setValue(1,setup.getInfo(howMany-1)); setup.setValue(howMany-1,null); howMany--; setup.organize(); } return temp; } public void printCode(){ //start recursive search if(encodedInfo.getNode().getLeft()!=null) printCode("0",encodedInfo.getNode().getLeft()); if(encodedInfo.getNode().getRight()!=null) printCode("1",encodedInfo.getNode().getRight()); } private void printCode(String s,node n){ if(n.getChar()!='\0') //check if reached character System.out.println(n.getChar()+" "+s); else{ //continue down tree if(n.getLeft()!=null) printCode(s+"0",n.getLeft()); if(n.getLeft()!=null) printCode(s+"1",n.getRight()); } } } class PriorityQueue { private tree[] setup=new tree[9]; private int howMany=9; public PriorityQueue(int[] freqs){ } public void organize(){ } private void swap(int i, int j){ } public tree getInfo(int i){ return setup[i]; } public void setValue(int i, tree temp){ setup[i]=temp; } }
Similar Threads
-
Null Pointer
By theen3my in forum AWT / SwingReplies: 3Last Post: 10-03-2009, 02:10 PM -
Null Pointer Execption
By bl00dshooter in forum AWT / SwingReplies: 2Last Post: 09-09-2009, 10:38 PM -
Null pointer exception
By Stephenmak in forum New To JavaReplies: 5Last Post: 04-01-2009, 02:17 PM -
null pointer help
By mayhewj7 in forum New To JavaReplies: 5Last Post: 02-17-2009, 11:51 PM -
Null Pointer Exception
By andre1011 in forum Advanced JavaReplies: 4Last Post: 02-07-2009, 03:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks