• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

phraseomatic code

 
John Frank
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i have no idea why it doesnt work. at least i cant find an error. i have tried google, found the same code, but it has some problems too.

so i ask myself if the code is the problem

[edited overlong lines - Jim]
[ June 28, 2006: Message edited by: Jim Yingst ]
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
Hope this solves the problem.


Were u getting an Array outofbounds Exception? Well that was because u were adding a random value to the String array length and the jvm did not find a value at that location.



[ June 28, 2006: Message edited by: Christian Nash ]

[ edited overlong line - Jim ]
[ June 28, 2006: Message edited by: Jim Yingst ]
 
John Frank
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
weird....it is exactly this way in the book "head first java".

for the code i posted:
phraseomatic.java:6: cannot find symbol
symbol : class string
location: class phraseomatic
string[] wordListtwo = .....

same for wordlistthree.

i have 3 errors with your change. i dont know exactly where they are because i put the code direct to the editor.

i ll keep heading forward maybe one day i ll find the problem *g*

thank you
[ June 28, 2006: Message edited by: John Frank ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case sensitive, and all language compilers are picky about the little details.

The error message is saying there's no such class as "string", and that's correct -- it's "String", with a capital S. I see two such errors in your first program.
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

Can't see how the (int)(Math.random() + oneLength) can work. Math.random() gives you a random double value.Then adding oneLength which is 12 and then typecasting it into an int will give you back 12 or more. Hence you should be getting an Array Indexoutofbounds Exception since there is no element for wordListOne[12].
[ June 28, 2006: Message edited by: Christian Nash ]
 
dee dee three three
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Couple of things ( one already mentioned ) - Java is heavily typed, so make sure strings are Strings.

Secondly, try this ...

int rand1 = (int) (Math.random() * oneLength);
int rand2 = (int) (Math.random() * twoLength);
int rand3 = (int) (Math.random() * threeLength);
( * rather then + )

HTH

D
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic