19

this thing keeps coming up I checked that all my source files are utf8 encoded, and Im using '-encoding UTF8' flag with both scalac and scala command line tools
any ideas?

thank you

deepblue
  • 8,426
  • 13
  • 48
  • 60
  • same problem was had here http://www.mail-archive.com/liftweb@googlegroups.com/msg09623.html the recommendation to fix it was the stuff that I tried without effect – deepblue Dec 18 '09 at 19:58
  • Windows or some other OS? That's extremely relevant in this case. Also, paste of the error and a small sample file would be very helpful. – Daniel C. Sobral Dec 18 '09 at 20:27
  • In fact... is that error compiling or running? – Daniel C. Sobral Dec 18 '09 at 20:30
  • thanks Daniel. the error is running, Im running on Ubuntu but editing from Windows using jEdit (but via sftp plugin so I think its editing it in place on the ubuntu machine). it compiles fine. \n the error is: \n "error: IO error while decoding /home/.../filename.class with UTF-8 \n Please try specifying another one using the -encoding option" – deepblue Dec 18 '09 at 20:35
  • Without an example, that's going to be tough to track down. It is being compiled on Ubuntu, I assume? And I assume you are not copying the .class file around, are you? Too much missing information still. :-( At this point, I advise going to scala-users mailing list, and providing much more details about what you are doing. – Daniel C. Sobral Dec 18 '09 at 20:52
  • ah, sorry. yes its being compiled on Ubuntu so its not a WIndows/LInux incompatibility, and the class file is not being copied around, just stays in place. I have a whole bunch of jars and other classes on my class path that Im point to via scala/scalac "-cp". As I mentioned above Im using '-encoding UTF8' to both scalac and scala, to make sure thats being passed in correctly. I tried doing a "file sourcefile.scala" on the main file Im compiling and it just tells me its a ASCII java code file, but ASCII being a subset of UTF8 I dont think thats a problem. – deepblue Dec 18 '09 at 21:02
  • I just asked the question on scala-user mailing list http://old.nabble.com/scala-%E2%80%9Cerror:-io-error-while-decoding%E2%80%9D-%E2%80%9Cwith-utf-8%E2%80%9D-td26849825.html – deepblue Dec 18 '09 at 21:15

4 Answers4

7

I encountered this problem running sbt "test" with Main.scala, for the indicated reason that it wasn't saved in UTF-8. I fixed it by changing Eclipse Main.scala "File / Properties / Text file encoding / Other" to "UTF-8" and saving.

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
user43702
  • 71
  • 1
  • 1
  • 2
    When you do this, you may notice font changes around special characters (such as long dashes in comments, if you've pasted them from a webpage), which has tripped me up before. – David Koelle Nov 18 '13 at 17:17
7

Just to document this, the problem is that the program was being run like this:

scala filename.class

Instead, it should be run like this:

scala package.hierarchy.Object

Where Object is the name of an main-containing object that you wish to run.

Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
5

I was having this error trying to set a classpath to launch the scala interpreter like scala-2.8 /path/to/jars/*.

The solutions in this thread Setting multiple jars in java classpath solved my problem; apparently the interpreter was attempting to open a jar file as if it was a text file containing scala commands.

Actually, I noticed that just putting the classpath in quotes prevents this message. The message means it is trying to load a .jar file as a scala program to be interpreted. It can't since it's binary.

scala-2.8 "/path/to/jars/*" works fine. The classpath and asterisk is then expanded by Java, not the shell.

Community
  • 1
  • 1
JAL
  • 21,295
  • 1
  • 48
  • 66
0

This will be rare, however in my case this happened because I had a few files that had file ownership set to the company I am consulting at. This not the normal file ownership under security but the microsoft azure protection encryption that you can disable using right click -> File ownership -> Personal (if there is a business domain set there, it is encrypted and needs to be decoded). Windows apps can open the file normally but using non-ms tools, like winrar and seemingly this case, it could not decode the file. Ideally there should be a way to work with the encrypted files but I'm not going to spend time on that here! :)

Julescs0
  • 11
  • 2