Moving and vanishing lines of code; trouble with Eclipse's XML Editor

Go To StackoverFlow.com

94

Sometimes my code moves on its own or just disappears in the Eclipse XML editor.

Yikes!

When I highlight the affected code, the highlighted lines try to correct themselves. But when I scroll or drag the mouse in the opposite direction the code shifts again. In essence I will have repeating, missing, and broken lines of code being displayed from an otherwise error free file. The files affected do compile and if I close / re-open them this problem goes away, for the moment. Any ideas on what's happening?


Addition: Jeff Axelrod provided a link to a new bug report with Google.

2012-04-05 14:39
by Sam
Sounds like a graphics issue to me. What's your OS and Eclipse version - s.d 2012-04-05 16:10
Vista and Eclipse 3.7.2 I looked around in the Eclipse bug site, but no luck. Maybe I missing a descriptive keyword - Sam 2012-04-05 16:20
I'm having the same problem. Win7 Pro 32-bit and Eclipse 3.7.2 with android 17.0.0... Same scenario as you describe in your answer. Can't find any bug reports either - Pat 2012-04-18 02:40
I'm also experiencing this, it's driving me crazy... In my case, using Windows XP with eclipse indigo. The issue happens always I switch from graphical layout to the xml edito - mdelolmo 2012-07-31 08:15
I too suspected this might be a graphics card issue. There is a known problem where Eclipse has redraw issues in the package explorer. However the symptoms are quite different - Jeff Axelrod 2012-08-30 17:21
Android bug report filed here - Jeff Axelrod 2012-08-30 17:23


32

This bug is (finally) fixed in ADT 21. The fix is now available in ADT 21 Preview 9, posted a few minutes ago, here: https://android-review.googlesource.com/#/c/44936/1

The reason you get weird visual artifacts is that if a file contains broken DOS line endings (multiple carriage returns without a newline for each carriage return), Eclipse gets very confused. That's Eclipse issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=375421 .

There are two parts to the fix: (1) First, ADT was fixed such that it no longer introduces these \r\r sequences into the document. This makes sure that you don't get new documents which triggers the weird editing behavior, but it does not retroactively fix older documents with these line endings, so if you open them, you still get weird editing behavior.

(2) Second, there's a new lint check which looks for broken line endings in documents. This runs incrementally, so if you edit an XML file which has this problem, ADT will add an error marker for this problem -- along with a quickfix to perform surgery on the document to fix it.

In short: Get ADT 21 Preview 9; run Lint on your projects and look for any complaints about files containing broken line endings, and if it finds any, apply the quickfix. From now on, further edits with the layout editor should keep the files consistently formatted.

FYI, the relevant fix is here: https://android-review.googlesource.com/#/c/44936/

Instructions for easily updating SDK Tools and the Eclipse ADT plugin are here: http://tools.android.com/preview-channel

-- Tor (from the Android tools team)

2012-10-18 00:58
by Tor Norbye
Thanks for taking the time to respond in person, so far it works great! For those who don't want to download the source code and build the tools locally, simply follow these two steps to install a pre-built version. (Read Installing the Eclipse Plugin if you forgot how to do step two. - Sam 2012-10-23 00:01
Works great for me. I'm in Eclipse Juno. Just went to Help > Install new software > What is already installed? Then I selected all the Android stuff from Google, selected Update, and now life is good again - rodrigo-silveira 2013-01-07 16:22


32

After some tests, I have found that the option "Automatically format the XML edited by the visual layout editor" (in Preferences | Android | Editors) might be the culprit here.

With my tests, I've found that changing a property (such as the layout_gravity) while in Graphical Layout design mode always screw up the visual display of the file when I go back to the XML (text) mode when this option is ON but that I have no problem when it's off.

If you want to format the XML upon your return from the Graphical Layout design mode, simply use the shortcut Ctrl+Shift+F. Also, I didn't see any problem with using the option "Format on Save"; even when I use it in the Graphical Layout mode; so you can use Ctrl+S instead while you're still in the Graphical Layout mode to both save and format your XML.

I've tried other editors options like "Show range indicator" or "Use characters to show changes in vertical ruler" but I didn't see any difference in behavior with activating or de-activating these options.

Finally, to correct the visual display of the file when it's corrupt; I found that using the shortcut: Ctrl+A, Ctrl+C, Ctrl+V is a little easier than closing/reopening the file. This is equivalent to making a Select All, Copy, Paste; effectively copying the whole XML file over itself.

2012-06-08 11:10
by SylvainL
Using ADT version 20120624... and Indigo Service Release 2 and SDK Tools Rev 20, and with "Automatically format the XML..." not active, I still have lines disappearing and turning into other lines - Brian 2012-07-17 19:12
Try with Juno. At this time, I'm no longer able to reproduce this bug with Juno. However, there are other bugs with Juno, too. For example, at one time with two XML files opened, the delete key was acting on the wrong file: trying to delete one character in one file was instead deleting a character in the other file. However, the Backspace key was OK. I will also have to change the default eclipse.ini configuration because from time to time, I get an error message about a lack of heap space when trying to run the EXE on the emulator. Did you check for both the 32 bit and 64 bit versions - SylvainL 2012-07-19 18:00
I believe I was using only the 32-bit version - Brian 2012-07-23 15:26
This is the best answer to date because it reduces how often this error occurs, but it does not eliminate it so the question is still open - Sam 2012-09-12 20:40
I still do have it this problem sometimes but not with the Graphical Editor: instead, it's with the AndroidManifest.xml file; which use another editor. This is with the latest version - Juno but I must admit that lately, I didn't have much time to work on my Android application so I cannot really tell for sure - SylvainL 2012-09-18 16:12
Still got problem with Juno + lastest ADT.It seem happen when i don't have enough ram - Nam Trung 2012-10-03 16:27
With Win7 Enterprise + Juno + latest ADT, "line vanish" glitch disappears when i format text by using CTRL + SHIFT + F shortcut as said in this post.. - GiveEmTheBoot 2012-11-20 19:01


12

Still experiencing this bug on Juno (Eclipse 4.2.0, ADT r20).

My fix: Go to Window -> Preferences -> Android -> Editors. I have both "Format XML using the standard Android XML..." and "Use Eclipse settings for indentation...." checked. This solved the problem for me.

2012-08-05 00:42
by Vaiden
No. Just uncheck the "Format XML using the standard Android XML...". It will fix the weird XML glitch, but also you have to live with the Eclipse convention - tom_mai78101 2012-09-13 13:26
Personally I prefer the Eclipse convention; the Android one doesn't differentiate between open-tag closing bracket (>) and standalone-tag closing bracket (/>) for determining whether to precede with a space (the option is limited to both or neither). Seems like a trivial issue, but for some reason I find it highly irritating - JAB 2013-05-29 16:33


12

EDIT: contain faster method, so it was bring to top:

Ctrl+F -> fill like that:

  1. "Find"          "\r\r\n"
  2. "Replace"    "\r\n"
  3. Switch "Regular expression" to ON
  4. hit the "Replace all" button
  5. Ctrl+A
  6. deselect text.
  7. be happy =)

Original was here: Just don't hide that issue, if you may fix it. Some times even closing the XML file didn't help.

For fix it let's look at the reason of it. First of all Turn On "Show Whitespace Characters" (Window > Preferences > General > Editors > Text Editors > Show whitespace characters )

Then back to your XML-file.

enter image description here

In scaled image you may see the difference of "\n"-symbol colors;

then just put cursor to that symbol, which is more dark.
enter image description here

look, two lines was selected 0o... that's may be the reason!

so just delete it, and press "Enter" or "Return" button for add "\n" symbol. enter image description here
Hope it help you.


also you may find the other symbol of endline:
enter image description here


Just delete it too, and your XML will have a great look!

P.S. sorry for hyperlinks, i'm newbie and on SO i can't upload image or more than 2 links. so hope you'll get the point without additional pictures ;)

P.P.S. Thx to guy who vote up, now i can provide this with images.

2012-10-02 13:48
by Dvide Leprechaun
Thanks a lot. I couldn't get the top voted comment to work but this one worked great - public static void 2013-11-20 14:56


4

I had the same difficulty and finally found the solution: Right click in the editor, select Source/Cleanup Document.

2012-10-07 11:39
by pcs


0

I had the same issue. The following steps were the solution. Link suggest its worked for others.

  1. Go to Preferences -> keys
  2. Unbind copy, paste, and cut (hit "apply", then "ok")
  3. repeat step 1
  4. Restore unbound commands from step 2 (I didn't restore cut, but I'm sure you'd be fine)

Notice there are 2 bindings for each of the 3 commands

  1. Unbind secondary function for both copy and paste (leave ctl+c/ctl+v [copy/paste] bound)

At this point you should only have 2 bindings set to perform copy/paste (i.e., ctl+c/ctl+v)

  1. Hit apply -> OK

This solution was found here.

2012-08-19 02:41
by Stephen


0

When this bug appears with new versions of ADT (which are mandatory for fixing and where bug should not appear often) just use Lint tool to fix it..

Find it in Lint warnings and click yellow bulb icon in upper right corner of that Lint warnings list..

Hope it will help somebody

2013-04-03 09:01
by Ewoks
Ads