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

Java Error Help

Options
  • 22-10-2013 12:36pm
    #1
    Registered Users 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 Posts: 1,109 ✭✭✭Skrynesaver


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


  • Registered Users Posts: 20 lkavo


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


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


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


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


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


  • Registered Users 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 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 Posts: 20 lkavo


    Still nothing.


  • Registered Users 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 Posts: 1,109 ✭✭✭Skrynesaver


    or even use printf escaping "%%"


  • Registered Users Posts: 20 lkavo


    I got it working. Thanks for the help :)


  • Advertisement
Advertisement