1

I do Java as part of my programming at college, and some of the tasks I've done I've needed to do at home. I run a 2017 MacBook Pro, but at college we have a HP desktop of some kind, and what I've had happen is if I've used a "£" symbol in my codes on the PC and then ran them on my Mac, the compiling brings back an error.

This is the code where I use the symbol:

public void depositMoney()
{
    int request = 0;
    System.out.println("How much money do you wish to deposit into your RunshawPay account? Min: £2.50 / Max: £360.00");
    System.out.print("£");
    String depositRequest = inputScanner.nextLine();
    try//type check
    {
        request = Integer.parseInt(depositRequest);
        if (request <2.50 || request >360)
        {
            System.out.println("Number cannot be outside of range. [range]");
        }
        else
        {
            System.out.print("Amount is ok!");
        }
    }
    catch (NumberFormatException ex)
    {
        System.out.println("Input needs to be integer. [type]");
    }

}

This is the error I recieve on the Terminal:

ModularValidation2.java:60: error: unmappable character (0xA3) for encoding UTF-8
    System.out.println("How much money do you wish to deposit into your RunshawPay account? Min: �2.50 / Max: �360.00");
ModularValidation2.java:60: error: unmappable character (0xA3) for encoding UTF-8
    System.out.println("How much money do you wish to deposit into your RunshawPay account? Min: �2.50 / Max: �360.00");
ModularValidation2.java:61: error: unmappable character (0xA3) for encoding UTF-8
    System.out.print("�");

I have showed this error to my tutor, who was as stumbled by it as me. I've tried to replace the characters by pressing the key into the editor (I'm using Sublime). Does anyone have any idea as to why this is happening and what a solution may be? Many thanks!

  • 2
    You need to know what character set was used when saving the file (likely Cp1252), you either need to convert the file from that character set to UTF-8 (which is the default used on MacOS), or you need to explicitly specify the character set when compiling. – Mark Rotteveel Nov 27 '18 at 18:45
  • Thank you! I've managed to get it running for now with the encoding with Cp1252 so I'll use that for now. I only need the code to run on my Mac while I finish it so no worries on converting the file! Thank you! :) – dylanpurser Nov 27 '18 at 18:51

0 Answers0