Unmappable character for encoding Cp1252 when trying to compile Java program

4.7k views Asked by At

I tried making a Hello World program in Java, but am getting a CP1252 error:

import acm.program.*; 
public class test extends Program
{
    public void run() { println(”Hello world!!!”); }
} 

Here's the errors:

C:\>javac -cp acm.jar test.java
test.java:4: error: unmappable character for encoding Cp1252
public void run() { println(ÔÇ?Hello world!!!ÔÇ?);
                              ^
test.java:4: error: unmappable character for encoding Cp1252
public void run() { println(ÔÇ?Hello world!!!ÔÇ?);
                                               ^
test.java:4: error: ';' expected
public void run() { println(ÔÇ?Hello world!!!ÔÇ?);
                                          ^
test.java:4: error: not a statement
public void run() { println(ÔÇ?Hello world!!!ÔÇ?);
                                             ^
test.java:5: error: reached end of file while parsing
}
 ^
5 errors`

The simple test.java program is obviously correct and I don't know what the issue is.

How do I resolve the CP1252 encoding error?

1

There are 1 answers

1
George Stocker On BEST ANSWER

The issue is that you're using smart quotes instead of the actual quote character.

Here's a 'fixed' version of your code:

import acm.program.*; 
public class test extends Program
{
    public void run() { println("Hello world!!!"); }
} 

Note the difference between " and .

To fix this (and it depends on your keyboard, I think), you should be using the " character that's immediately to the left of your Enter key.