Within one of my methods, I want to switch layouts into a secondary one. But for some reason, the setContentView can't see the layout in the folder. The following images show this:
My layout folder
I then ran the code
setContentView(R.layout.saveg_w_name) //I know this name is correctly spelled and everything since I clicked the createLayout
And yet it still gives the cannot resolve symbol error. Is this a bug with android studio or am I doing something wrong
Just restart your android studio and again check.
If it still doesn't solve your issue, try invalidating caches.
click File(Menu)->Invalidate Caches/Restart
Please click on this link for the image:
Second image for new project:
Please see Image above. I have added many button/view to the layout. But there is no constraint line/ alignment line that I used to see when I add new items to the layout. Also, I don't see my view/button show up in the design view.
What is wrong? How can I fix this. So, I can design my layout quickly in the design view?
One note, when I create the first app project. I suppose to see the word "Hello world" in the middle, but I didn't see it this time also
Clean and rebuild your project then you will be able to see it, the problem occurred because your code contained some error when it was building so building failed and android studio don't show preview if that happens.
Cleaning and rebuilding will solve your problem
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.
During build of my android application I am getting the following error:
:app:mergeDev_testingDebugResources
error: found an invalid color.
I don't get any line of code or even which file it is having a problem with. I have a large number of outstanding changes (stupid me) which I don't want to roll back - but I'm totally stumped as to how to work out what is wrong.
For future reference - this error is what you get if you have added an image as a 9-pack and it isn't yet properly formatted with the black pixel borders. The error message could be far more helpful, i.e. actually saying which file the error occurs with would be nice, but the solution is just to go through all your 9 pack files in Android Studio and open then save each of them.
First of all, check your layout directory in file explorer bcoz when you have made changes in the main layout file then you could have changed respective example: v-21 or v-13 layout file too. This error occurs when you apply some element property which is not supported by previous versions like v-21.
I hope I have given detail about this, if any explanations are needed plz let me know.
Yes, the problem is in 9-path image. At least in my case.
The problem was in black lines in the borders of image. It should be only black and transparent. Nothing else. In my case there was shadow from view with alpha. With photoshop I remove any color pixels of borders (except black lines)
At Android Studio launch Analyze -> Inspect code. Then resolve all errors
In my case , i have done mistake while writing color,
like -
<color name="mainBackground">#8e00ed></color>
then look i have added extra symbol this-">" after my color ,
it should only be
<color name="mainBackground">#8e00ed</color
Then it worked fine for me.
Just check between two symbols "only color code" should come "no extra symbols,no apostophies,no semicolons" should be there.
Thank You!!!
I'm trying to programmatically set the ID of a TextView simply using the line
titleView.setId(R.id.installedTitle);
but I get an error at this line that states:
"installedTitle cannot be resolved or is not a field"
What could be wrong here?
You have (maybe) not cleaned your Project, so it may be possible that your R File has not been generated. You may also have some errors in your Project (xml files) so the R wont get generated aswell. You may also not have used setContentView() before and loaded the Layout and/or the ID is not in your layout.