0

I'm trying to compile 3 java files located in: /var/www/PhpProject2/Solutions/5/9/1/ on my Computer (Linux Ubuntu).

I used the following command in my shell: javac /var/www/PhpProject2/Solutions/5/9/1/*.java

and it outputs 100 errors that looks like this:

error: unmappable character for encoding UTF8 mergeSort(arr); // ���� �� ����� ������ ��� ������ ���

with an arrow pointing at one of the � signs.

This is new to me because for all I know Compilation gets rid of all comments in my code, not treating them as errors.

What I have tried so far:

change the command to: javac -encoding UTF-8 /var/www/PhpProject2/Solutions/5/9/1/*.java

look for the file encoding with: file -bi /var/www/PhpProject2/Solutions/5/9/1/UnionIntervals.java

and then I tried: javac -encoding text/x-c++; charset=iso-8859-1 /var/www/PhpProject2/Solutions/5/9/1/*.java

all ended up with the same error.

AvivLevi815
  • 37
  • 11
  • Try `hexdump -C` to check what is actually in your file at one of the positions the compiler complains about. – Markus Apr 24 '16 at 20:16
  • Your issue may be similar to this one: http://stackoverflow.com/questions/4995057/unmappable-character-for-encoding-utf-8-error – Michael Markidis Apr 24 '16 at 20:55
  • @MichaelMarkidis I read this one before.. it was solved by re-saving the file so actually there was no problem at all and if there was one it was in the actual code- not in the comments like in my case. – AvivLevi815 Apr 24 '16 at 21:16
  • @Markus , in this case it's a simple character in a foreign language.. anyway this should have no effect because it is inside a comment – AvivLevi815 Apr 24 '16 at 21:18
  • The fact that it's in a comment isn't relevant. The error is coming from the input routines, not the syntax analyser. The file isn't well-formed from the point of view of its character set. `javac` is just as entitled to complain about that as any other program. – user207421 Apr 24 '16 at 22:23
  • No, the whole source file including the comments needs to be parsed by the compiler, therefore the comments do matter. By default obviously UTF-8 is used by the compiler, and your source file isn't in that encoding. It isn't ASCII either. So you need to specify the correct encoding on the command line. The string you used in your second command isn't a valid name for an encoding. What is the encoding you actually used for the file? – Markus Apr 24 '16 at 22:27

1 Answers1

0

Given the following minimalistic Java file:

> cat test.java 
// ä

The following command gives exactly the error you describe:

> javac -encoding utf8 test.java 
test.java:1: warning: unmappable character for encoding utf8
// ?

When using the correct encoding, the file is processed without errors:

> javac -encoding iso-8859-1 test.java 

This is because the Java compiler needs to parse the whole file (including the comments). The comments are only stripped off after the parse.

Markus
  • 3,155
  • 2
  • 23
  • 33
  • thank you so much ! this actually worked for me, but how did you figured that iso-8859-1 is the correct encoding ? – AvivLevi815 Apr 25 '16 at 15:36
  • Educated guess from the output of the `file` command you provided. By the way, I think you should get your environment sorted out. The encoding of your source file should match your default encoding, then you won't have to deal with this kind of issues. What's the content of your `LANG` environment variable? – Markus Apr 25 '16 at 16:07
  • I do not know , how can I find out ? – AvivLevi815 Apr 25 '16 at 19:06
  • In a console, type `echo $LANG`. – Markus Apr 25 '16 at 19:44
  • OK, it says: en_US.UTF-8 – AvivLevi815 Apr 27 '16 at 18:14
  • Therefore the Java compiler defaults to UTF-8. So should your editor, but obviously you ended up with ISO encoded files. You should set up your development environment or editor or whatever you are using to use UTF-8 as well. – Markus Apr 27 '16 at 19:40