1 Replies - 107 Views - Last Post: 09 October 2012 - 12:32 PM Rate Topic: -----

#1 codejilly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 09-October 12

exception in thread main nullpointerexception error

Posted 09 October 2012 - 12:28 PM

[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;
}
}]

Is This A Good Question/Topic? 0
  • +

Replies To: exception in thread main nullpointerexception error

#2 DimitriV  Icon User is online

  • >not activating your almonds
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,681
  • Joined: 24-July 11

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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1