2 Replies - 170 Views - Last Post: 09 October 2012 - 01: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 - 11:51 AM

[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

Is This A Good Question/Topic? 0
  • +

Replies To: exception in thread main nullpointerexception error

#2 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

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

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: exception in thread main nullpointerexception error

Posted 09 October 2012 - 01:32 PM

Please :code:
or select code and click the [ code ] label at the top of the editing window
and avoid duplicating thread. Other thread closed
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1