pbl, on 10 October 2012 - 06:42 PM, said:
i slapped in the print line again because as you see i have again modified my selectionsort method.....
so here is the code with the print line in:::
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, 12);
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){
for(Track1 t : tracks){
System.out.println(t);
}
}
}catch (IOException ex){
Logger.getLogger(TrackMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Track1[] selectionSort(Track1[] tracks, int mpos){
Track1 tmp = null;
for (int i = 0; i < tracks.length - 1; ++i){
mpos = i;
for (int j = i + 1; j < tracks.length; ++j){
System.out.println(mpos + ") " + tracks[mpos]);
if(tracks[j].compareTo(mpos) > 0)
mpos = j;
}
tmp = tracks[i];
tracks[i] = tracks[mpos];
tracks[mpos] = tmp;
}
return tracks;
}
}
and these are the errors i got....
0) null Exception in thread "main" java.lang.NullPointerException at TrackCollections.TrackMain.selectionSort(TrackMain.java:67) at TrackCollections.TrackMain.main(TrackMain.java:38) Java Result: 1

New Topic/Question
Reply




MultiQuote


|