XML Problems with Eclipse / Android SDK - android

I'm fairly new to eclipse and android development, and I'm having what must be a pretty simple error to fix. I've done some development on my laptop and never encountered these errors. (I currently only have access to public computers, and have eclipse and the SDK installed on a USB drive.)
The first strange thing I noticed when editing the main layout was that there is no properties window to allow easy editing of various layouts and objects. (There was on my old computer) I have not been able to figure out how to get this window to appear.
So after adding one textView and modifying its properties by hand, I receive the following two errors when I attempt to run the program. (No code has even been added yet, just one textView)
http://i.stack.imgur.com/9VGT0.png (Link to screenshot of error, only have 6 rep)
All I've done is change the textView to have center gravity, fill_parent layout width, and a textSize of 22sp. I've tried googling the errors to figure out what I'm doing wrong but have been unsuccessful. Anybody encounter this before? Also, if anybody knows how to make the properties window appear it would be a great help.
Thanks in advance

When compiling Android stuff in Eclipse, you have to press the "Run" button with a .java file open, not with .xml file open. No idea why, but the glitch is there and you'll soon remember to avoid it.
To fix the current state, delete the 'main.out.xml' file (it was automatically created on compile). Then in the 'Problems' tab (the one on your screenshot), manually delete each problem it shows you. After that, press Run again with a .java file open and it should solve whatever is there now.

You get the properties window back from the "Show View" dialog, which is accessible from the "Window" -> "Show View" -> "Other ..." menu.
Once the dialog is open, look in the "General" folder for "Properties".

right click the .xml file and go to Open With... there are many ways to open it. I prefer the xml editor but there is also a layout editor available.

Your XML is not well-formed, e.g. mismatched elements, mismatched quotes, etc. Show your XML for more specific assistance.

Related

Android Studio 2.1.1 using tabs, not spaces, even though tabs are not checked in Settings

When editing Java files, if I'm at the end of the line and I type the Enter key, it starts the next line properly indented 4 columns, to match the line above. That's OK but it's indenting with a tab, not spaces, even though in File>Settings>Editor>Java>Tabs and Indents the checkbox for Use tab character is unchecked, and always has been.
If I just type the tab key I also get a tab, not spaces.
I never want to use tab characters; I always want to use spaces. I don't have this problem in Eclipse or Microsoft Visual Studio so it's not some system setting for my PC. Is there some other setting in Android Studio for this?
Edit: I tried the suggestion that Omar Al Halabi (below) made and it didn't work but while testing it I noticed something interesting: This tab problem seems to mainly apply to the beginning of the line, i.e., if I type Enter on the previous line, it immediately tabs over to the first indent position on the following line, using real tabs, not spaces. On the other hand if I'm typing some text on an existing line, once I've typed a little text, if I hit tab, it then tabs over using spaces.
hope this helps,
check Use Tab Character,
give all that values to zero than you not get space on enter in java code, like in below image,
one more thing is you have to change your code format settings or may need to disable it
This is not an answer, but I don't have enough reputation points to post my questions as a comment.
- Is this issue happening in all your Android Studio projects?
- Are you using the Default scheme for the general File->Settings->Editor->Code Style and also for the Java Code Style?
- Have you tried making a new Java Code Style scheme at the Project level for just one project as a test?
EDIT: This is a brute-force/shotgun approach.
Rename your \Users\<username>\.AndroidStudio2.1 directory (e.g., .AndroidStudio2.1_orig)
Open Android Studio and force it to use the default settings by choosing the "I do not have a previous version of Studio or I do not want to import my settings" option when the "Complete Installation" dialog window appears.
Run a recursive 'diff' between the new and old .AndroidStudio2.1 directories to find any changes you've made to the default settings so you can re-apply them. The settings are kept in XML files so they are human-readable. Keep an eye out for any differences that may affect Android Studio use of tabs & spaces, because those might be the source of the problem.
If this does not work, then you may have to re-install Android Studio.
Try opening Settings->Editor->Code Style->Java. Check "Use tab character". Click OK.
Then go to File->Invalidate Caches\Restart -> Invalidate and Restart.
Then, again, go to Settings->Editor->Code Style->Java. Now uncheck "Use tab character" and hit OK.
If it still doesn't work change tab size and indent and then restore them back if you want.
The IDE tries to position the lines as if they belong to the same block. Also very likely you had used the tabs on the previous line. You can try to deactivate Detect and use Existing file indents for editing

Random "red x" warning but no information given. Where should I start?

I'm new some I apologize if this sounds stupid.
I'm using the latest version of Eclipse and and have an "Android Project" going. I have a little red x on one of my folders. Usually a "pop" will tell me what is wrong but this one says nothing. When I open activity_main.xml (which is inside the folder there are no problems that I can see). Is this a glitch or is this normal?
I'm not sure where to start to make it go away.
How I got there;
I started a new folder under "res". I'm following a book and it said to call it Layout Land and start another activity_main.xml inside. Everything is fine but that x is there over the folder.
Any info will help. Thanks!
Go to Window -> Show View -> Problems. Then you should have a Window in which you can read what the problem is.

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

Sometimes my code moves on its own or just disappears in the Eclipse XML editor.
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.
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)
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.
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.
EDIT:
contain faster method, so it was bring to top:
Ctrl+F -> fill like that:
"Find" "\r\r\n"
"Replace" "\r\n"
Switch "Regular expression" to ON
hit the "Replace all" button
Ctrl+A
deselect text.
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.
In scaled image you may see the difference of "\n"-symbol colors;
then just put cursor to that symbol, which is more dark.
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.
Hope it help you.
also you may find the other symbol of endline:
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.
I had the same difficulty and finally found the solution: Right click in the editor, select Source/Cleanup Document.
I had the same issue. The following steps were the solution. Link suggest its worked for others.
Go to Preferences -> keys
Unbind copy, paste, and cut (hit "apply", then "ok")
repeat step 1
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
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)
Hit apply -> OK
This solution was found here.
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

No Graphical layout editor in Android

I imported an Android project in Eclipse. Somehow, the layout editor does not open automatically when I open a layout! After I open it, it gives me the 'Graphical Layout' tab but it is still an empty frame! The only difference I see from my previuos projects is that the top drop-down menu has an option called "Locale" while the older ones had "Any locale".
Please advise.
Restart eclipse. I always close eclipse when this error happens and restarting it after that and my problem got resolved.
Something similar happened to me today and I found that if I closed the window/tab and opened again a few times it fixed itself. It was annoying though. Also try going into the xml tab and edit something in there and go back to the Graphical Layout.
Something similar happened to me a few versions of ADT for eclipse ago.
EDIT
Ok it has just happened to me once again. What I did to resolve was to change the Android version to something else. It's the drop down box beside the Create... button. That made it reappear
I have the same problem, it goes away if I switch to XML view and make a single edit, and then save. Then switch back to graphical layout and the error is gone.
It wasn't working for me no matter what I did. But it started working again when I deleted a bunch of projects in my workspace. My theme for eclipse was also deleted when I did this too, I'm not sure why.

Where is the Visual Editor for Eclipse with the ADT plugin

I thought ADT should come with a visual editor for building GUI : Easy way to build Android UI?
However, I just cannot find it. I was wondering where is the Visual Editor for Eclipse with the ADT plugin.
I can run HelloWorld application without problem. However, whenever I click on main.xml at the left navigation tree layout folder, here is what I get. What I wish to get is a WYSIWYG editor.
Select your main.xml file. At the bottom of eclipse you can see a Layout tab, click on it and eclipse will open the android gui editor.
As Paul Kearny previously noted, to resolve issue with seeing "Design" tab instead of "Graphical Layout" follow these 2 steps:
1) Delete project from the left of the screen, without deleting the source files
2) File -> Import -> Existing Projects into Workspace, browse and select your workspace folder and open your project
Graphical Layout problem fixed!
If you want to edit the layout visually, rather than through XML, click on the Layout tab at the bottom left of the main.xml window (in your screenshot, just above Problems).
Also note, there are issues with displaying some of the widgets. For example, the ListView does not render. So, my hint is to change ListView to just a View, then work out the details of the layout so you can get the colors, relative-ness, etc. Then switch it back to ListView. There is one other widget that I cannot recall off the top of my head ...
To resolve issue with seeing "Design" tab instead of "Layout" or "Graphic Layout", I had to:
1. Delete the project from Eclipse without deleting the source
2. Shut down and restart Eclipse
3. Import the project back in
You could probably skip step 2, but I did it just to make sure.
Hope this helps anyone else who has the same issue.
If your view is showing Design|Source for the .xml file right click on the main.xml and select open with - android common XML editor. Simple.
If it is happening to one particular xml, you can delete the file (make sure you copy the content first), create new xml and paste the content again.
I recommend that any serious Android developer stay far, far away from Eclipse/ADT Design View. This is a time-wasting tool that sorely lacks the attention it would need from Google to make it worth serious consideration. It doesn't render the views as a real device would. There is no way to bind dynamic data. Does it work with fragments (I think not)? For it to work properly and have useful features would weigh down Eclipse further and make it unacceptably slow. In my very humble opinion, the entire strategy for ADT's ui-design tools has failed.
Thus, the recommendation is: edit Android XML layout files by hand and use the only reliable testing mechanism you have for layouts: actual devices. You can always fallback on the emulator - but the emulator performs 50x - 100x slower than an actual device. I'm not exaggerating. Pick your poison!
new fix, took me forever to get this fixed, really simple....delete the xml file and undo the deletion (ctrl+z), double click and there you go. Hope this helps someone as it did me. No shut down required.
If you see "Design" tab instead of "Graphical layout", just close the project and open it again.

Categories

Resources