Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java Error Help

  • 22-10-2013 12:36PM
    #1
    Registered Users, Registered Users 2 Posts: 20


    Does anyone know why this error is happening in my programme?

    Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'y'
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.io.PrintStream.format(Unknown Source)
    at java.io.PrintStream.printf(Unknown Source)
    at sovdev.main(sovdev.java:192)
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    Does line 192 of sovdev.java contain a printf statement with an invalid format specifier?, perhaps "%y"


  • Registered Users, Registered Users 2 Posts: 20 lkavo


    Nope all my .f are %s and changing theses to %S doesn't seem to make any difference


  • Registered Users, Registered Users 2 Posts: 2,088 ✭✭✭henryporter


    Maybe stick the code up here so we can have a look


  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    Have you tried adding a debug logging of the values you are attempting to convert?


  • Registered Users, Registered Users 2 Posts: 20 lkavo


    if ((totalPrice >= 20.00) && (totalPrice < 40.00)) {

    discountAmount = totalPrice*DISCOUNT1;

    netPrice = totalPrice - discountAmount;

    System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
    System.out.printf("% yielding you a discount of %s£",discountAmount);
    System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
    }
    else if (totalPrice >= 40.00) {

    discountAmount = totalPrice*DISCOUNT2;

    netPrice = totalPrice - discountAmount;

    System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
    System.out.printf("% yielding you a discount of %s£",discountAmount);
    System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
    }

    else {
    System.out.printf("Your total has come to % £", totalPrice);
    }

    and the error is

    Exception in thread "main" 0.05java.util.UnknownFormatConversionException: Conversion = 'y'
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.io.PrintStream.format(Unknown Source)
    at java.io.PrintStream.printf(Unknown Source)
    at sovdev.main(sovdev.java:183)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 8,449 ✭✭✭Call Me Jimmy


    lkavo wrote: »
    if ((totalPrice >= 20.00) && (totalPrice < 40.00)) {

    discountAmount = totalPrice*DISCOUNT1;

    netPrice = totalPrice - discountAmount;

    System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
    System.out.printf("% yielding you a discount of %s£",discountAmount);
    System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
    }
    else if (totalPrice >= 40.00) {

    discountAmount = totalPrice*DISCOUNT2;

    netPrice = totalPrice - discountAmount;

    System.out.printf("You have recieved a discount value of %s",DISCOUNT1);
    System.out.printf("% yielding you a discount of %s£",discountAmount);
    System.out.printf("Your final cost after the discount has been applied is %s £" , netPrice);
    }

    else {
    System.out.printf("Your total has come to % £", totalPrice);
    }

    and the error is

    Exception in thread "main" 0.05java.util.UnknownFormatConversionException: Conversion = 'y'
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.io.PrintStream.format(Unknown Source)
    at java.io.PrintStream.printf(Unknown Source)
    at sovdev.main(sovdev.java:183)


    Is it this line, you might have to add a symbol (backslash?) to allow the '%' to be printed? Like you're trying to print out the % to the screen but it might be misinterpreting as a formatting '%'...

    EDIT: Actually not sure what you're doin with that first '%' on its own?


  • Registered Users, Registered Users 2 Posts: 20 lkavo


    Still nothing.


  • Registered Users, Registered Users 2 Posts: 8,449 ✭✭✭Call Me Jimmy


    lkavo wrote: »
    Still nothing.

    Well try removing that first percentage in that line and see if it compiles.


  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    or even use printf escaping "%%"


  • Registered Users, Registered Users 2 Posts: 20 lkavo


    I got it working. Thanks for the help :)


  • Advertisement
Advertisement