[public class TrackMain {
static Track1[] tracks = new Track1[12];
public static void main(String[] args){
FileInputStream fs = null;
try {
try {
FileInputStream fis = new FileInputStream("G:\\OOP II\\ASSIGNMENT 1\\tracks.txt");
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
System.out.println(tracks.length);
String strLine;
while((strLine = br.readLine()) != null){
System.out.println (strLine);
}
System.out.println("----------------------------------------------------------------");
dis.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
selectionSort(tracks);
fs = new FileInputStream("G:\\OOP II\\ASSIGNMENT 1\\tracks.txt");
DataInputStream ds = new DataInputStream(fs);
BufferedReader b = new BufferedReader(new InputStreamReader(ds));
String strln;
while((strln = b.readLine()) != null){
if(tracks != null)
for (int i = 0; i < tracks.length; i++){
System.out.println(tracks[i]);
}
}
}catch (IOException ex){
Logger.getLogger(TrackMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static void selectionSort(Track1[]tracks){
for (int pos = 0; pos < tracks.length-1; pos ++){
Track1 min = tracks [pos];
int minpos = pos;
for(int i = pos + 1; i < tracks.length; i++){
if(tracks[i].compareTo(min) < 0){
min = tracks[i];
minpos = i;
}
}
swap(tracks,minpos,pos);
}
}
private static void swap(Track1[] t, int i, int j){
Track1 temp = t[i];
t[i] = t[j];
t[j] = temp;
}
}][/code]
when i run the code i get the following error:
at TrackCollections.TrackMain.selectionSort(TrackMain.java:63)
at TrackCollections.TrackMain.main(TrackMain.java:39)
nothing i try seems to be working
2 Replies - 113 Views - Last Post: 09 October 2012 - 01:32 PM
#1
exception in thread main nullpointerexception error
Posted 09 October 2012 - 11:51 AM
Replies To: exception in thread main nullpointerexception error
#2
Re: exception in thread main nullpointerexception error
Posted 09 October 2012 - 12:21 PM
Can you wrap the code in CODE Brackets correctly? This is awful to try to read.
#3
Re: exception in thread main nullpointerexception error
Posted 09 October 2012 - 01:32 PM
Please
or select code and click the [ code ] label at the top of the editing window
and avoid duplicating thread. Other thread closed
or select code and click the [ code ] label at the top of the editing window
and avoid duplicating thread. Other thread closed
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|