Why do my java codes result in "compilation error" even if it is a short and simple code like this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why do my java codes result in "compilation error" even if it is a short and simple code like this

https://code.sololearn.com/c9kUf8r7Q2Aw/?ref=app

12th Mar 2019, 12:54 AM
matt
16 Answers
12th Mar 2019, 1:35 AM
Denise Roßberg
Denise Roßberg - avatar
+ 8
Personally, I can't stand using the web version either. It's much quicker for me to use a real IDE for writing, running, and debugging. Then, I can copy paste to share with the community. The lag and timeout on SL can really slow down the code writing process for me. But, that's simply my preference. 🙃
12th Mar 2019, 4:22 AM
David Carroll
David Carroll - avatar
+ 7
BTW... I was slow to post my solution earlier and later noticed others posted working versions already. So, I removed my answers. Denise Roßberg I haven't had any issues with copy and pasting from Sublime in either Windows or Mac. I will need to test doing this with IntelliJ. However, I'm surprised such characters would appear in IntelliJ.
12th Mar 2019, 2:03 AM
David Carroll
David Carroll - avatar
+ 6
Did you copy it from your pc? After removing all white spaces i got an error about illegal characters. So I think the code playground interpretes some characters wrong.
12th Mar 2019, 1:12 AM
Denise Roßberg
Denise Roßberg - avatar
+ 6
Denise Roßberg I was about to mention the same thing. Invisible characters seem to be interfering with proper compilation.
12th Mar 2019, 1:13 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Denise Roßberg Unicode. Most likely custom IDE encoding, some which support UTF-8 would compile the code without errors (treating and possibly using the symbol as whitespace for indentation purposes). http://www.fileformat.info/info/unicode/char/00a0/index.htm Interesting though. Code Playground doesn't tell me anything about u00a0. I simply received a "Compilation Error" message without any hint as to what went wrong. Did you compile it using an offline compiler, or... ?
12th Mar 2019, 1:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Just FYI, I've been copypasting my work in and out of Jetbrains products, IntelliJ included. I've never met with such issues. I would advice looking into your IDE settings for encoding options.
12th Mar 2019, 5:30 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Hatsy Rei the illegal character is \u00a0 (mentioned in the error message) but I don't know which character it is and from where it comes. Has it to do with the used IDE?
12th Mar 2019, 1:21 AM
Denise Roßberg
Denise Roßberg - avatar
+ 4
Hatsy Rei Now the question is: How to find such illegal characters? Removing all white spaces is very annoying.
12th Mar 2019, 1:45 AM
Denise Roßberg
Denise Roßberg - avatar
+ 4
It's funny how this is a question that was bothering me, and I brought it up earlier in a different thread. This way of phrasing the question is indeed better and clearer than the way I phrased it there. See here: https://www.sololearn.com/Discuss/1687269/?ref=app It's really annoying, especially to me as a beginner. I can never know if my code didn't compile properly because of an error in the code, or because of Code Playground's limitations. On a few occasions I've had code that wasn't compiling in Code Playground, yet a copy/paste into IntelliJ and it worked just fine!
12th Mar 2019, 5:07 AM
Shtisim Lukshen
Shtisim Lukshen - avatar
+ 3
Denise Roßberg and Hatsy Rei thanks! I have a feeling you are right, and i did copy from my pc. I'll try manual entry into code playground and see if that works. Thanks again!
12th Mar 2019, 1:20 AM
matt
+ 3
David Carroll I mean in general. Because this problem is relatively common and especially beginners are very confused. I would like to have a tip on how to copy code from the PC to the Code Playground.
12th Mar 2019, 1:54 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
matt Maybe an alternative to copy and paste: You can use the code playground on the website (using your PC).
12th Mar 2019, 2:13 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
David Carroll The last time the problem arose, the coder had used Netbeans. I use Ecplipse, but have never tried to copy the code because I write for Sololearn directly in the Code Playground.
12th Mar 2019, 2:09 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Denise Roßberg great suggestion. I'll give it a try!
12th Mar 2019, 2:15 AM
matt
0
Denise Roßberg thanks for the link! I used IntelliJ to compile it on my pc and it ran without error there. Entry of code manually into code playground doesn't work very good using the keyboard of my mobile phone, so I copied/pasted a few codes I wrote and they all have the same compile error. I think your explanation makes total sense!
12th Mar 2019, 1:37 AM
matt