Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

While Loop Problem(s)

 
Andrew Garczynski
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can some please point out the error im having with this code?


These are the errors i'm getting:
I:\2nd Year\OOP 2\WhileLoop.java:15: cannot find symbol
symbol : variable string
location: class WhileLoop
string.Format("Rate: %.2d \nAmount £: %2d \nEuros €: %.2d")
^
I:\2nd Year\OOP 2\WhileLoop.java:14: cannot find symbol
symbol : method showMessageDialog(<nulltype>,java.lang.String,double,double)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(null, "The conversion total is: " +
^


 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those compiler warnings seem out of sync with the code you posted.
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would expect the variables to go inside the string format method, just checked and yep, on the inside as a variable length argument list.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having the variables added to String.format(...) with + operators should’t be a compiler error. The additional ) is, however. You can suffer an Exception when the % tags don’t match their arguments, but that is a problem for later on.
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Having the variables added to String.format(...) with + operators should’t be a compiler error. The additional ) is, however. You can suffer an Exception when the % tags don’t match their arguments, but that is a problem for later on.


see you learn something every day.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Garczynski wrote:
I:\2nd Year\OOP 2\WhileLoop.java:15: cannot find symbol
symbol : variable string
location: class WhileLoop
string.Format("Rate: %.2d \nAmount £: %2d \nEuros €: %.2d")
^


Read the message very closely. Remember, Java is case-sensitive.

I:\2nd Year\OOP 2\WhileLoop.java:14: cannot find symbol
symbol : method showMessageDialog(<nulltype>,java.lang.String,double,double)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(null, "The conversion total is: " +
^


The error message is telling you exactly what's wrong. (They usually do.) You're calling JOptionPane.showMessageDialog(null, String, double, double), but if you look at the docs for JOptionPane, you'll see there is no such method.
 
Andrew Garczynski
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it to work, thanks guys
Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic