Android Studio paste issue - android

Whenever I try to paste some lines of code into a file in Android Studio it acts like this:
Copied lines overwrite existing lines below caret position.
It pastes several times for a single command (I copy 7 lines and press Ctrl+V just once and it gives me 49 lines)
I don't know if this is some weird coding feature that I'm unaware of.
How can I turn this behavior off and make it work the ordinary way?
Update
it's not a keyboard issue. No problem in Visual Studio!

In case someone else should face a similar issue in the future, mine was fixed after I marked and then unmarked Column Selection Mode (Alt+Shift+Insert).
Still strange but it resolved the issue!

I have the same issue I fix by clear android studio cache
File ---> Invalidate Caches/Restart
Another solution
instead using ctrl + v Use ctrl + Alt + Shift + V

Probable Reasons:
You are copying from somewhere where lines are hiding inside compact brackets
Your keys/keyboard is gone might generating 7 times same signal for a command (7*7 = 49)
Please check

In android studio 2.2 or above hold Control key then drag the layout or widget to duplicate

Press the 'insert' button on your keyboard (labeled "ins")

Related

How can I make code beautiful in Android Studio as like as VSCode?

VSCode have a great option what helps developer to make code more beautiful. I mentioned in the given picture. It indicates each brackets related to which case. I've worked on flutter in VSCode but now I've decided to work on Android Studio for some reasons and unfortunately I don't know where I can find it. Did you guys know how I can fix it?
I have to apologize for Title because I don't know what this option is?
You can also use following command to make more beautiful and easy
(1) Search Everywhere (Press Shift Twice / Press Shift Twice)
(2) Recently Opened Files (CTRL+E/Command+E)
(3) Find Action (CTRL+Shift+A/Command+Shift+A)
(4) Generate Code (ALT+INS/Command+N)
(5) Override Methods(CTRL+O/Command+O)
(6) Delete Line at Caret/Cursor (CTRL+Y/Command+Y)
(7) Collapse/Expand Code Blocks (CTRL+- / Command+-)
(8) Collapse/Expand Whole activity code (CTRL ALT - /CTRL ALT +)
(9) Reformat Code (CTRL+ALT+L / Command+Option+L)
Just Press CTRL+ALT+L on Windows or Command+Option+L on Mac. The android studio will reformat all the code for you. And the good part is that it works for XML layouts as well.
Use CTRL+ALT+L to reformat your code.
Use CTRL+ALT+O to optimize imports.
Use CTRL+ space to complete code.

Not able to create new color item in colors.xml file

The error I am getting is : "The color "colorRed" in values has no declaration in the base values folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier less... "
I have tried clean project and rebuild and also tried invalidate cache & restart but still that error not going.
I have attached screenshot of colors.xml file
I solved the problem cleaning the project and build it again. If it doesn't work, invalidate caches and restart.
I'm using Android Studio 3.2
Invalidate Caches with File > Invalidate Caches / Restart... > Invalidate and Restart
Its a bug, and it happens for dimensions and possibly others. (Not just colours.) First time I saw it was the day I upgraded to AS 3.2.1.
But you may not need to clean, rebuild or invalidate caches. Try this:
(A) Cut and save (e.g. to NotePad) the flagged XML from the base folder and all qualified folders.
(B) Paste it back in, starting with the base folder
Update: 10Jan2019 [Dumb and dumber]
In fact, not even cutting and pasting is necessary. Suppose the following line is giving the problem...
<string name="edit">Edit</string>
Just change the tag to anything. e.g.
<xstring name="edit">Edit</string>
Then wait a second for removal to occur before changing it back
It's a weird bug. but here's a Workaround:
Open the file in android studio and select all the text.
now cut all the text and paste it in the same place.
(or simply, go to the problematic file and press- 'ctrl+A' --> 'ctrl+x' --> 'ctrl+v')
this does not change anything but apparently solves the errors.
This error occures still in AS3.4C10... so it is not solved yet.
For me, the only remedy is to select "Invalidate Cache/Restart" from File menu.
RG
Cleaning Project solved my problem
I might be a bit late to the party, but the latest update of Android Studio (v3.2 Canary 17) seems to have solved this bug.
I had a similar issue with colors and resources and updating Studio seems to have fixed it.
Hope this helps!
This is not an error. It is the IDE bug.
Run the project and error will be automatically resolved.
I quit and restarted Studio and the error went away.
It has occurred for me many times. This appears an Android Studio bug to me.
This may really not be an error though Android Studio shows it temporarily, most likely due to different code in generated files.
Most of the time this error goes if we run build or clean project and rebuild project. Android studio restart is not always required.
If that does not work invalidate cache and restart android studio.
This Error can appear for any of xml files. Not just colors. If you see too many errors, it's surely this one. However, sometimes the error occurs even for just one line. That can be difficult to identify. If you think the error is totally illogical, try a rebuild.
Very rarely I have seen this kind of absurd errors in Kotlin or Java files as well which go away on clean build.
Open Resources->Add new Resource -> choise "New Color value.." other defend on you
I using in android 3.3.1
I'm late to the party, but I fixed this problem by just altering the typing work. I added some more spaces to make it look cleaner and more readable and suddenly the red underline and error messages were gone. Must have been a bug of sorts.
(Studio 3.3.3)
I had same error. I just ran the project with same condition and the error went away.
Did you paste it in from a spreadsheet? If so, just check that everything that looks like a double quote is in fact a double quote. Spreadsheets are a great way to build lengthy resource files, concatenating cells of xml formatting text around cells of names & items etc, but you might find that some of those cells you began with a double quote (e.g. ") will usually have a special open/close-quote character instead. These look like the real thing, but they won't be recognised as xml text indicators, so if e.g. your object name never gets initiated, you'll get this error.
In my case there was literally "no declaration in the base values folder" because the xml file wasn't in the base values folder, after selecting create new file, although the directory tree showed it to be in the values folder.
Find your xml file in the directory tree, select refactor, select move, and look at the path. If there's an invisible addition to the path, delete it back to the proper folder.

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

Android Studio not showing any errors?

I don't know what happened
but when i copy paste a code or write something
No Errors were shown
See the picture below in which i copied a code but no imports yet
But Android studio doesn't show any error.
Even when i Ctr + Alt + O It doesn't imports anything
Is their any setting to get it back or anything else?
I already tried updating all available updates
Sounds like you may be in power save mode. Check it on the File menu, just above Exit. While in power save, code inspection is disabled.
To get code inspection running again, you can either: 1) exit power saver mode, or 2) run inspection manually with Inspect Code... on the Analyze menu.
On the right side, click on the smiling face and pull the progress bar at the right:
I fix this problem by reset setting: File > Manage IDE Settings > Restore Default Settings.
After reinstall plugins, I realized that butter knife plugin was the problem
Clean your Project and press ALT + ENTER for import into android studio
in logcat view
try to remove any filter or filter by your application
Click on bottom right corner icon in android studio and uncheck the Power Save Mode
On the right bottom side, click on the user face and uncheck the power Save Mode.
For me none of the ones above helped.
I found the solution by doing this.
Analyze --> Inspect Code... --> Check - "Whole Project"
Also if this doesnt work out. Check if one of your classes need to implement some methods and the compiler is not recognizing that.
Try also:
Code --> Implement Methods...
go to this path => C:\Users\AppData\Local\Google\AndroidStudio4.1\plugins
find => Groovy_Console_Plugin_8542.zip
check it is extracted if not then => extract hear
then you will get result
note: check your Highlighting level (inspection level) is on syntax
Just remove the ./gradle folder and then relaunch Android Studio to download/install the Gradle automatically.
Invalidate caches and restart helped me
What fixed mine in Android Studio V. 2022.1.1 Canary 3 was that I had "none" selected for the highlighting which showed up as "OFF" in the top-right corner of the code box:
Clicking on that popup box that was now there:
And I noticed it said "Highlight None". clicking on that blue link gave me 3 options:
Selecting the "All Problems" brought me to this stats popup box:
Once that was done doing its thing I was finally presented with errors in my code! (which really isn't good but its good in this step-by-step guide):
On your right side , theres are colored squares next to the page scroll. Typee on the red square to see the error.
Following worked for me:
While opening a new project, be sure you connect your system with power,
restart and then enable safe mode and when the settings pop up
set the check for compile if not checked.
Good Luck

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

Categories

Resources