so you have to call
public Track1(String t, String art, String alb, int len){
with the data read from the file and store the Track1 object created into your array
34 Replies - 335 Views - Last Post: 10 October 2012 - 02:30 PM
#31
Re: exception in thread 'main' nullpointer exception error
Posted 10 October 2012 - 01:28 PM
#32
Re: exception in thread 'main' nullpointer exception error
Posted 10 October 2012 - 01:35 PM
pbl, on 10 October 2012 - 08:28 PM, said:
so you have to call
public Track1(String t, String art, String alb, int len){
with the data read from the file and store the Track1 object created into your array
public Track1(String t, String art, String alb, int len){
with the data read from the file and store the Track1 object created into your array
i think i did that because i redid my main again and added this piece of code
when i called the selectionSort method....
here it is:
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 (int i = 0; i < tracks.length; i++ ){
String t = b.readLine();
String art = b.readLine();
String alb = b.readLine();
int len = b.read();
Track1 t1 = new Track1 (t,art,alb,len);
tracks [i] = t1;
System.out.println(t1.toString());
}
}
}catch (IOException ex){
Logger.getLogger(TrackMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
#33
Re: exception in thread 'main' nullpointer exception error
Posted 10 October 2012 - 01:43 PM
Not really
int len = b.read();
this read as a int a single character from the file, does not read the ASCII representation of an integer
You wioll have to readLine() in a String and then use Integer.parseInt() to store in a int the String representation of the number in the file
int len = b.read();
this read as a int a single character from the file, does not read the ASCII representation of an integer
You wioll have to readLine() in a String and then use Integer.parseInt() to store in a int the String representation of the number in the file
#34
Re: exception in thread 'main' nullpointer exception error
Posted 10 October 2012 - 01:59 PM
pbl, on 10 October 2012 - 08:43 PM, said:
Not really
int len = b.read();
this read as a int a single character from the file, does not read the ASCII representation of an integer
You wioll have to readLine() in a String and then use Integer.parseInt() to store in a int the String representation of the number in the file
int len = b.read();
this read as a int a single character from the file, does not read the ASCII representation of an integer
You wioll have to readLine() in a String and then use Integer.parseInt() to store in a int the String representation of the number in the file
i tried that by changing the code to this in calling the selectionSort method:
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((b.readLine()) != null){
for (int i = 0; i < tracks.length; i++ ){
String t = b.readLine();
String art = b.readLine();
String alb = b.readLine();
String len = b.readLine();
int n = Integer.parseInt(len);
Track1 t1 = new Track1 (t,art,alb,len);
tracks [i] = t1;
System.out.println(t1.toString());
}
}
}catch (IOException ex){
Logger.getLogger(TrackMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
and am still getting the same error....
this is bumming me out
#35
Re: exception in thread 'main' nullpointer exception error
Posted 10 October 2012 - 02:30 PM
Use a Scanner. 's'
That's the last code i'm posting on this
while(s.hasNext()) {
tracks[index++] = new Track1(s.next(), s.next(), s.next(), s.nextInt());
}
That's the last code i'm posting on this
|
|

New Topic/Question
Reply




MultiQuote



|