Results 1 to 3 of 3
- 02-15-2013, 06:40 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
NullPointerException for String array
I am making a PriorityQueue class for a small program, but it keeps giving(when i call on the push function) me a nullpointer exception in line 13:
.else if(hi==a.length)
I do not understand why, It'd be great if anyone here could help me out.
Java Code:public class PriorityQ { private String[] a; private int lo,hi; private boolean isSort; public PriorityQ() {String[] a=new String[1024];lo=0;hi=0;isSort=false;} public void push(String s) { if(lo>0){a[--lo]=s;} else if(hi==a.length) {this.resize(2); a[hi]=s;} else {a[hi]=s;} isSort=false; } ...Last edited by ivanblackz; 02-15-2013 at 06:57 PM.
- 02-15-2013, 07:01 PM #2
Re: NullPointerException for String array
In your constructor, you're declaring a new String array with the same name as the class variable String array.
That is some strange formatting, by the way. Try this to get a better idea of what you're doing:
Java Code:public PriorityQ(){ String[] a=new String[1024]; System.out.println(a); System.out.println(this.a); lo=0; hi=0; isSort=false; }How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-15-2013, 07:10 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
NullPointerException when there is data in array
By anoorally in forum New To JavaReplies: 3Last Post: 02-08-2012, 11:33 PM -
NullPointerException when accessing array
By aianta in forum New To JavaReplies: 3Last Post: 10-15-2011, 10:19 PM -
text into array...nullpointerexception
By csuever in forum New To JavaReplies: 4Last Post: 04-01-2011, 12:08 AM -
Please help on nullpointerexception error.. Cannot initallize the array properly.
By tvenhc in forum New To JavaReplies: 8Last Post: 03-31-2011, 06:09 AM -
NullPointerException converting String to double
By infaddict in forum New To JavaReplies: 3Last Post: 07-19-2008, 06:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks