I copied and pasted code and Eclipse is giving me an error. I can fix it by deleting the spacing at the beginning of the lines but that is very tedious. It is the most recent version. Any ideas?
Try turning on display of control characters. Under Preferences > General > Editors > Text Editors. There is a checkbox labeled "Show whitespace characters". Then you could potentially do a global replace if that is the issue.
I have seen such errors in the past in other language (ActionScript) in eclipse. The problem there was that the used whitespace character was not the usual one to encode a blank but the one that encoded a blank that should not be broken apart into two lines. I would expect normaly this should not be an issue in Java because it uses unicode ... but probably your file has some other encoding (not unicode)!?
You should check:
Does the encoding of your file support unicode (in the eclipse "Properties" of the file). Probably changing the encoding solves your problem.
Look in some hex editor into the problematic file and check the character of the problematic blanks. Probably you have copy/paste your code from some webpage and there was such a character used to prevent the browser to break the code into multiple lines.
There are different unseen characters. What I do is to paste to a text editor (such as Notepad ++) and I say remove formatting. It removes these unseen characters and copy from it and paste it to the eclipse without any problem.
Related
i've started developing in IntelliJ in Java, created a new gradle project, added a few libraries but encountered a problem that a string is not being filled with cyrillic symbols - instead i get incorrect symbols (screenshot attached). How can i fix it? It has something to do with encodings - I tried a lot of suggestions on the web but nothing helped. Cheers!
Just change all encodings into UTF-8 (or other preferable encoding) and reload all java files into UTF-8.
You must know how to do first part (if you don't: File(top left corner of your window)>Settings>Editor>File Encodings).
The second part is also easy: just click on encoding in bottom right corner of the window and choose UTF-8 (or other preferable encoding).
Then you will have window like shown below. Choose "Reload" and enjoy. If you still have questions you are free to ask.
Here better description: https://www.jetbrains.com/help/idea/encoding.html
I am using selenium webdriver with java and trying to verify some texts I find on a page.
The text contains diacritics like ţ ă etc.
The problem I encounter is when I run my test from the command line using maven; I need to do this because I will be integrating them into Jenkins.
So I have a simple assert in my test:
Assert.assertEquals("some text with ţ", driver.findElement(text).getText());
which fails and I don't know what is the right way to make this work.
I have read that the default encoding for strings in Java is UTF-16, so when the text is taken from the page with getText, the string is already encoded and I suppose that means that the characters are lost. On the other hand, I don't know if the comparing text itself "some text with ţ" is interpreted ok.
Has anyone had problems similar to this? And how have you solved them?
Thanks
Maven is even issuing a warning specific to your error:
WARNING: character encoding not set. Using the platform default encoding, i.e., the
build is platform-dependent!
or a similar message.
The solution is to:
make sure you save the Java source code files in UTF-8;
make sure you explicitly configure the encoding in pom.xml (a setting on the Compiler plugin).
I am writing a program in java with Eclipse IDE, and i want to write my comments in Greek. So i changed the encoding from Window->Preferences->General->Content Types->Text->Java Source File, to UTF-8. The comments in my code are ok but when i run my program some words contains weird characters e.g San Germ�n (San Germán). If i change the encoding to ISO-8859-1, all are ok when i run the program but the comments in my code are not(weird characters !). So, what is going wrong with it?
Edit: My program is in java swing and the weird characters with UTF-8 are Strings in cells of a JTable.
EDIT(2): Ok, i solve my problem i keep the UTF-8 encoding for java file but i change the encoding of the strings. String k = new String(myStringInByteArray,ISO-8859-1);
This is most likely due to the compiler not using the correct character encoding when reading your source. This is a very common source of error when moving between systems.
The typical way to solve it is to use plain ASCII (which is identical in both Windows 1252 and UTF-8) and the "\u1234" encoding scheme (unicode character 0x1234), but it is a bit cumbersome to handle as Eclipse (last time I looked) did not transparently support this.
The property file editor does, though, so a reasonable suggestion could be that you put all your strings in a property file, and load the strings as resources when needing to display them. This is also an excellent introduction to Locales which are needed when you want to have your application be able to speak more than one language.
In Java I tried to write a String as an output to the console. The length of the String is 20166 characters. After printing the string to the console only second half of the String appears.
The whole string is one long line:
What it looks like:
From the beginning there is a lot of whitespaces (which are supposed to be alphanumeric characters) and after that there is the rest of the string displayed properly.
I tried to change console encoding from default to UTF-16 and UTF-8, but it didn't help.
The String I am trying to output is text content crawled from a specific webpage (http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery). If I crawl a different webpage there is no problem.
How I process the string:
I use a webservice to get the text content from the webpage. The returned String (text contet) is printed properly (whole). I need to process this string so I change all characters to lowercase and replace all multiple whitespaces with the single one.
textContent.toLowerCase().replaceAll("\\s+", " ");
After lowercasing the characters I am still able to print whole string properly, but after replacing the multiple whitespaces with one, the beginning of string is not visible.
Do you have any idea what the problem is?
Thakns in advance for any help.
This is no bug. It is 1 of the changeable settings that Eclipse includes to make the output more readable.
It can be changed by going to Windows --> Preferences --> Run/Debug --> Console and then unchecking "Limit Console Output" which is ON by default.
For more information and details about these settings visit:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Frun-debug%2Fref-console.htm
This works on STS any version too. This would help printing complete console output.
What are the preferences for the console? Especially check the settings "Fixed width console" plus "Limit console output". Maybe your console simply can't hold that many characters in one line.
In Eclipse if you go to preference and in the drop-down, you can see RUN/DEBUG option if you click on that RUN/DEBUG drop-down you can see the console button and there you can adjust the "Fixed width console" plus "Limit console output"
[EDIT] Now Eclipse eventually has to cut the data in the console since it doesn't have infinite amounts of memory. If the console is still cut off, you can use this trick: Open the "Run Configurations" dialog (Found in the drop down menu for the green "run" button).
The tab "Common" tab has options in the "Standard Input and Output" group at the bottom to save a copy of all output in a file. You can then use your OSs tools to examine this file.
Also note that very long lines can make Eclipse slow (i.e. it can hang for a couple of seconds). This is due to a bug in the regexp matching patterns for Exception stack traces. If that happens, limit the line length to 1000 characters or less.
This is especially a problem with Spring which sometimes creates exceptions that have 50'000 characters in the message.
If you have a similar problem with the CDT Global Build Console, see here: Eclipse CDT Build Console output not displaying entire compiler output
Check whether the console buffer size is enough for your case, in Preference. Usually it's 80000 characters, just in case it's been changed.
Check this bug: Long Lines not printed to console, which is a duplicate of Bug 23406, opened in 2002 and not fixed yet! I just discovered it in Eclipse 2020-06, then I tried also the very old Ecipse Mars and it works. They says that the problem affects not only the console but also editors. A comment says "This bug has too many dups for a WONTFIX".
I am using netbeans 6.1 on 2 computers.
on one of them the program:
public static void main(String argv[])
{
System.out.println("שלום");
}
prints normally, and the on the other question marks.
what can be the difference between the 2 environments?
edit:
on both computers
Control Panel \ Regional and Language Options \ Advanced
is set to hebrew
edit:
Thank you Michael Burr,
but the value of the encoding is already UTF-8.
Maybe this something with the JVM?
edit:
I have installed Eclipse and the problem occurs there as well.
I also tried reading the hebrew from a file with the same result.
edit:
System.getProperty("file.encoding");
returns "Cp1252"
I tried
System.setProperty("file.encoding","UTF-8")
but the question marks remains.
Thanks,
Ido
Make sure that NetBeans is set up with an encoding that supports Hebrew characters. From the NetBeans Wiki:
To change the language encoding for a project:
Right-click a project node in the Projects windows and choose Properties.
Under Sources, select an encoding value from the Encoding drop-down field.
You can't set the "file.encoding" property with System.setProperty(); it has to be set on the command line when the JVM is started with -Dfile.encoding=UTF-8. The value of this property is read during JVM initialization and cached. By the time your main method is invoked, the value has been cached and changes to the property are ignored.
Is Hebrew installed by default? Could be that a language pack isn't installed?
Control Panel > Regional and Language Options > Languages. Select the 'Install files for complex script and right-to-left languages (including Thai)' option. This will install support for Hebrew. You'll probably need an OS disc.
How exactly are you running the program? Where does it print its output? It could be as simple as netbeans or the console using different fonts, one of which does not include Hebrew characters.
To eliminate encoding problems during compilation, try replacing the Hebrew characters with their unicode escape sequences and see if the result is different.
I think I misunderstood your problem (I thought that the characters were not being displayed in the NetBeans editor properly). The exact steps to solve your problem might depend on the version of the OS you're running on. Win2K, WInXP, and Vista all have slightly different dialogs and wording unfortuantely.
Take a look at this help page for the JVM:
http://java.com/en/download/help/locale.xml
It sounds like you've already configured the system like it should be, but the devil is in the details - there are several different 'locale' settings on a system that might affect this (and for all I know the JVM might throw in one or two on its own).
http://www.siao2.com/2005/02/01/364707.aspx
Usually it's the default encoding on:
Control Panel \ Regional and Language Options \ Advanced
(Select Hebrew on the combo)
You'll have to restart after changing this setting.
What helped me is this (on Win7):
No one answer from above doesn't work.
I spent about an hour, but had figured out, that the problem is located not in the String encoding, but in default encoding, which is used by IDE from the start-up.
So, to get Hebrew, Arabic, Russian etc symbols in Netbeans console output you need to modify netbeans.conf.
Search for the key netbeans_default_options and add -J-Dfile.encoding=UTF-8 into the quotes.