[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){
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);
}
}]
[ public 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);
}
}]
[public static void swap(Track1[] t, int i, int j){
Track1 temp = t[i];
t[i] = t[j];
t[j] = temp;
}
}]
1 Replies - 76 Views - Last Post: 09 October 2012 - 12:32 PM
#1
exception in thread main nullpointerexception error
Posted 09 October 2012 - 12:28 PM
Replies To: exception in thread main nullpointerexception error
#2
Re: exception in thread main nullpointerexception error
Posted 09 October 2012 - 12:32 PM
Does Track1 need to be initialized before you use it? Does it take a constructor in the New argument?
Page 1 of 1
|
|

New Topic/Question
This topic is locked



MultiQuote



|