aspose file tools*
The moose likes I/O and Streams and the fly likes java code compile but won't run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "java code compile but won Watch "java code compile but won New topic
Author

java code compile but won't run

gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
Hello everyone,

I test code from Head First Java book about Jukebox3

(if you have this book please see on page : 537 this is code about Jukebox3, and on page 550 about class Song implements Comparable<Song> chapter 16 about collection and data Structure)

this the code about Jukebox3 :



and this the Song code :



this code compile but when I start, it shown results :


java.io.FileNotFoundException: SongList.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at Jukebox3.getSongs(Jukebox3.java:22)
at Jukebox3.go(Jukebox3.java:13)
at Jukebox3.main(Jukebox3.java:9)
[]
[]


Q : what mistake on this code?

note : I create this java code using eclipse indigo

please help

thanks
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

The problem is : The system cannot find the file specified .

Temporarily put the SongList.txt file in C:/TEMP. Then change File("SongList.txt"); to File("C:/TEMP/SongList.txt");
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
I think the problem is not about the path,

I try to create temporary directory according on your advice C:/Temp/SongList.txt

and then I run it, but it's error and shown :

java.lang.ArrayIndexOutOfBoundsException: 2[]

at Jukebox3.addSong(Jukebox3.java:34)
at Jukebox3.getSongs(Jukebox3.java:27)
at Jukebox3.go(Jukebox3.java:15)
at Jukebox3.main(Jukebox3.java:11)
[]


note : this code (jukebox3) I download from : webpage

and the result still same

Q : what's mistake on this code??

please help

thanks
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426



Note this is a different error, so you've temporarily moved past the file problem.

gong pex wrote: what's mistake on this code??


That's the trick of software development. A good developer will problem solve until all the problems are solved. Out of bounds exception is generated when you try to reference an item that is past the boundary of the result set.
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
That's the trick of software development. A good developer will problem solve until all the problems are solved. Out of bounds exception is generated when you try to reference an item that is past the boundary of the result set.


Q : so in other word this code deliberately made wrong?

I'm still new learn java, how can I solve this problem??

please help

thanks
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

What is your input ? What are the contents of your SongList.txt file ?
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
What is your input ? What are the contents of your SongList.txt file ?


Here my SongList.txt :



please help me

thanks
Chris R Barrett
Ranch Hand

Joined: Dec 05, 2013
Posts: 62
    
    3

Hi gong,

Your code indicates that each line will have four tokens separated by a "/":



But, your SongList.txt file has only 2 tokens per line:


The program is running out of tokens per line and generating the ArrayIndexOutOfBoundsException when it gets to the missing third token. You will want to fix the SongList.txt file format to match the required input.

Oh, and Roger is 100% correct - this is a completely unrelated issue to your original FileNotFoundException.

Cheers!
Chris
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
it's work

many thanks
Chris R Barrett
Ranch Hand

Joined: Dec 05, 2013
Posts: 62
    
    3

Hi gong,

That's great to hear!

I guess Mr. Moderator can knock this one off as closed. ;)

Cheers!
Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java code compile but won't run