• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java code compile but won't run

 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gong pex wrote:java.lang.ArrayIndexOutOfBoundsException: 2[]
[]


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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your input ? What are the contents of your SongList.txt file ?
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your input ? What are the contents of your SongList.txt file ?


Here my SongList.txt :



please help me

thanks
 
Chris Barrett
Bartender
Pie
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's work

many thanks
 
Chris Barrett
Bartender
Pie
Posts: 317
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gong,

That's great to hear!

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

Cheers!
Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic