文本编码错误:无法使用字符集 windows-1256 对文本进行编码

Error encoding text: Unable to encode text using charset windows-1256

我写了一个程序,但是当我想保存它时,我得到一个错误提示:

Error encoding text. Unable to encode text using charset windows-1256. First bad character is at line 13 column 40.

我不明白错误是什么。我正在使用 jGRASP。这是我的程序:

public class Point {
double x, y;
int counter=0; 

Point (double ex, double why){
x=ex;
y=why; 
counter++; }

public Distance (double x1, double y1) {
/* using Pythagoras c^2 = a^2 + b^2 
 where a is the horizontal distance (x − x1)
 and b is the vertical distance (y − y1)
 and c is the distance */
double a, b, c;
a = Math.pow(x - x1);
b = Math.pow(y - y1);
c = Math.sqrt(a + b);
}

public product (double x1, double y1) {
// using the dot product rule =>  A.B=(a1.b1)+(a2.b2)
double product = (x * y)+(x1 * y1);
}

public void setX (double ex){
x=ex; }

public void setY (double why) {
y=why ; } 

public double getX() {
return x; }

public double getY() {
return y; } 

public int getCounter() {
return counter; } 

} // end of class

第 13 行第 40 列是字符代码 8722。这看起来像一个减号(代码 45),但实际上不是。在第 14 行,第 36 列还有一个相同的。将这些替换为正常的负号,如果没有类似问题,则可以使用 1256 编码(您的系统默认值)保存文件。您很可能粘贴了代码或至少是来自某些 non-code 来源(例如网站或 MS Word 文档)的评论,这就是它们进入那里的方式。

您可以在编辑器中输入任何 Unicode BMP,但在保存时,如果您不指定其他编码,将使用您的系统默认编码。 1256 不支持所有这些字符。如果绝对必要,您可以使用 "File" > "Save As" 以另一种编码保存(但在这种情况下您不想这样做)。