• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java code compile but won't run

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 tji
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 tji
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your input ? What are the contents of your SongList.txt file ?
 
gong tji
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 tji
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's work

many thanks
 
Chris Barrett
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic