Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java Error Help

  • 22-10-2013 11:36am
    #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,089 ✭✭✭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