Computer Science Canada String Sorting HELP |
Author: | xxbow-pkerxx [ Tue Jan 02, 2007 7:36 pm ] | ||
Post subject: | String Sorting HELP | ||
Im a newer java programmer and i need major help the problem is that i keep getting an error (using drjava) the error NullPointerException: at java.lang.String.compareTo(Unknown Source) at insert1_1000.insertSort(insert1_1000.java:53) at insert1_1000.main(insert1_1000.java:32) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) the code:
|
Author: | xxbow-pkerxx [ Tue Jan 02, 2007 7:38 pm ] |
Post subject: | please reply |
please reply to me here or via e-mail Taha1234567890@hotmail.com |
Author: | McKenzie [ Wed Jan 03, 2007 9:15 am ] | ||
Post subject: | |||
Attach the data file. I tried putting empty strings in the array and it stops it from crashing. I'd guess you don't have 6000 lines in your file, or the file is not in the same folder. I find the placement of
odd, but It won't cause your problem. |
Author: | xxbow-pkerxx [ Wed Jan 03, 2007 2:39 pm ] |
Post subject: | |
heres the data files if testing 3 of them |
Author: | HellblazerX [ Wed Jan 03, 2007 8:12 pm ] | ||
Post subject: | |||
My guess would be in this line:
Since you started with current being 0, current - 1 will give you -1, so you'll be comparing with something that doesn't exist. I think Java will check all conditions inside the parentheses, regardless of whether the first condition is true or not. |
Author: | McKenzie [ Thu Jan 04, 2007 9:14 pm ] |
Post subject: | |
Oops, The FileIn.close() is causing the problem. Your program will read in the first 767 lines then die with it there. Just place it after your for loop. I haven't even looked at your sort, so it may or may not work. |