1 Replies - 121 Views - Last Post: 09 October 2012 - 11:44 AM Rate Topic: -----

#1 codejilly  Icon User is offline

  • New D.I.C Head

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

i keep getting exception in thread main NullPointerException error

Posted 09 October 2012 - 11:32 AM

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;


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);

}
}

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

Is This A Good Question/Topic? 0
  • +

Replies To: i keep getting 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: i keep getting exception in thread main NullPointerException error

Posted 09 October 2012 - 11:44 AM

Well before you get help, you need to put this code in code brackets and then post exactly what the error message(s) say.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1