| Author |
getting null pointer exception! how to fix it.
|
Rahul Shilpakar
Ranch Hand
Joined: Aug 29, 2006
Posts: 132
|
|
there is a text file having data in rows and column with positoning the tabs and \n . i am getting all rows. now the first element in row is a primary key in a (DB) table. and i want to do the operations on the other column. Problem is that when i retrives a row, at last its showing null charecter or space type. now for 124 id. its primary key in a table master table. and other column in mastertable having primary key 124 is its name. Am splitng a row on "\t" string and store in String array now it gives total 6 values in string array 123, 4, 30, no$, 0 and last is null i.e. nothing my code is DefaultSupString uses searchrecord class ------------- Exception java.lang.NullPointerException at supstring.SearchRecord.getRecordSet(SearchRecord.java:37) at supstring.DefaultSupString.itemaspv(DefaultSupString.java:24) at supstring.DefaultSupString.main(DefaultSupString.java:58) [ UD: added CODE tags ] [ July 14, 2007: Message edited by: Ulf Dittmer ]
|
Perform for today. Adapt for tomorrow.
|
 |
Rahul Shilpakar
Ranch Hand
Joined: Aug 29, 2006
Posts: 132
|
|
MORE elaborate about my test file presentation my_text_file.txt ------------------------------------------------------- | mid pid pv vt Ref FD TD | 123 9 25 no$ 0 | 124 9 25 no$ 0 | 125 9 25 no$ 0 | : | : | : | Problem: I am storing one row in string array i.e. String arr2[]={123,9,25,no$,0, , ,}.There is nothing in column FD & TD Now, how can avoid vlaues of FD TD to eliminate NullpointerException.? its giving exception in file Searchrecord.java file at if (temp==9){ dss.getSupplierString(arr2); // here am getting problem } please tell me . i am in need. [ July 14, 2007: Message edited by: Rahul Shilpakar ]
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
I think you just need to check each array entry for null before using it: Depending on your business rules, you can sometimes plug in a default value. Right after your split() you might fill in defaults: This is probably outsid ethe bounds for the beginner forum, but some times we can provide a special object that defines the behavior for missing data. That can avoid repetitive tests and lame comments in later code. Any of those ideas work for you? [ July 15, 2007: Message edited by: Stan James ]
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: getting null pointer exception! how to fix it.
|
|
|