• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

While Loop Problem(s)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: " +
^


 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those compiler warnings seem out of sync with the code you posted.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76856
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it to work, thanks guys
Andrew
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic