Layout resource files not recognized - android

I refactored a resource_layout file but android studio didn't recognize the change so I deleted the file but didn't check the safe delete boxes.
Now whenever I create any layout resource files they are not recognized in my project. Any help would be very appreciated!
Also, the old layout resource file I had deleted is still recognized in my code (even though it should be breaking).
I tried cleaning my project, rebuilding my project, making my project.
I also tried checking through the terminal to see if the original layout resource file I deleted was still somewhere in the project but it isn't.
MaterialEditText edit_name =(MaterialEditText)enter_name_view.findViewById(R.id.edit_name);
The enter_name_view doesn't exist anywhere but this line doesn't show any errors.

Related

Resource.layout/Id not found in Android Xamarin

I have a big Xamarin Android project where I recently added few new layout files. Ever since I added them, the build always failed with Resource.Id not found errors (complaining about not being able to find the UI components' ids, even though they are there, there are NO spelling mistakes). I tried cleaning and rebuilding, deleting bin and obj folders and cleaning & rebuilding, adding "MSBuild:UpdateGeneratedFiles" to properties of the project and then closing VS, cleaning & rebuilding - none of that worked. Since the errors were saying the UI components' ids were not found, these UI elements weren't included in Resource.Designer.cs file, so I figured that is the issue. I tried deleting Resource.Designer.cs file and rebuilding, and it got updated and included the missing UI components, but the issue is still there. I am kind of blocked at this point, any help would be much appreciated...
The errors look like this:
Error CS0117 'Resource.Layout' does not contain a definition for 'layout_exceptionfooter' BrockSolutions.SmartClear.GateScanning.MobileClient.Android C:\git\SmartSuite\SmartClear\Libraries\GateScanning.MobileClient.Android\Components\PassengerScanExceptionFooterComponent.cs 25 Active
enter code here
At first, check these layout files is in the layout folder which belongs to the Resources folder.
And then, check the file properties of them and make sure that the Build Action is set as AndroidResource. You can check it by right click the file and click the properties.
Finally, if your project is in a xamarin.forms project, please check the namespace of the .cs file.
If the problem still exists, you can post the code you used the layout files and an example of them.

Cannot resolve symbol R. [Tried all the solutions mentioned]

I am making an Android app. Due to some reasons, my current project files got all messed up. To solve this issue I created a new project in Android Studio and copied the files from the previous project to this new project.
I carefully copied all the layout, values, java files at their right location. I replaced the relavant content from the new manifest and gradle files with new content.
Everything looked perfect and then I got the "Cannot resolve symbol R" error.
I tried all the solutions like Invalidate Cache/Restart, Sync files with gradle, Rebuild Project, Clean Project etc. etc. etc.
Still couldn't fix it.
Can someone help?
Edit
Problem Details
1. I have correct package name everywhere (in AndroidManifest too)
2. I have proper and valid xml files
3. Even if I copied the files from other project the I've kept the project name and package names exactly the same.
4. I have only one app module.
Try to remove .R line from every java class .
You might have an error in one of your xml files, like a duplicated xml header. Check for every single one.
You can also update Android Studio as it now tells you the file and location of the error.
I strongly suggest you copy and paste your codes to individual right places if you want to move these to a new project. Copying folders and files to a newly created project would not work as there could be some lines that include your old folder paths
For example, your old project was in C://StudioProjects/YourProjectName so your codes should be in C://StudioProjects/YourProjectName/app/src/main/java/com/example/AppName but if you directly copy a file or folder to a newly created project, you could end up referencing the wrong path like C://StudioProjects/YourProjectName/app/src/main/java/com/example/NewAppName and this could blow your XML file which will lead to R cannot resolve symbol R.
Even though you put your folders in the same path, reference numbers changed in the new project.

Android studio - Can't find newly added internal assets

When trying to use any newly added assets I get the error:
com.badlogic.gdx.utils.GdxRuntimeException: File not found: bg.png (Internal)
The code is fine, since if I try to use an asset I added a few days ago it works fine. The naming is correct, and there are no capital letters or anything like that.
For some reason AS is not registering the newly added assets.
I've tried cleaning, synching and rebuilding, I've tried several files, nothing works.
What could be causing this?
Try this :
|__Run
__Edit Configuration
(in the left side)
__Default
__Application
In the right side choose Configuration tab . Under Working directory specify your android/assets path.

'Cannot resolve symbol' and 'No resource found that matches the given name' - not a duplicate

I opened my project in Android Studio yesterday and got red everywhere with 'Cannot resolve symbol' as the description. It was completely random as no changes had been made to either the project or AS since the last time I opened the project. I ended up updating Android Studio to 2.0 and trying a bunch of solutions I found online but nothing works.
Like this guy, I have already tried:
Rebuilding the project
Cleaning the project
Syncing with Gradle Files
Closing the Project, closing AS and relaunching / reopening
File > Invalidate Caches / Restart
Examining Lint, didn't see anything obvious
Double checking all support libraries are up to date in the SDK manager
Examining my Build.gradle, although no changes and it's the same as usual, the way it was working all the time.
I have also tried the following steps (from the accepted answer):
Exiting Android Studio
Backing up ymyour project
Deleting all the .iml files and the .idea folder
Relaunching Android Studio and reimporting project
I also tried:
Removing the 'proguard' entry in build.gradle
Changing to "Use default gradle wrapper" in preferences
Another solution is to move 'buildTypes' in build.gradle but 'buildTypes' is already at the bottom of the Android section
Don't mark this as a duplicate if the "duplicate" is someone who fixed the same problem by doing something that didn't fix my problem.
Here are some screenshots:
As you can see, the color 'white' does exist:
R errors everywhere as well:
These errors are everywhere too:
Why are there two res directories and why is the one with the necessary resources a sub-directory of the java directory? Could this be related? Screenshot here:
EDIT: I created a drawable directory in the main res directory and added one of the drawables that won't get picked up by build variants. It removed the relevant 'Cannot resolve symbol' error. But when I deleted the main res and tried try to move the whole res directory in the java subdirectory to the main directory I got the following error:
EDIT: I managed to build without errors by deleting the outer res directory, copying the one inside the java one, pasting that into the main directory then deleting the one inside the java directory. How these got moved around like that I do not know. Probably caused by following the 'solution' of deleting and importing the project again. Whether it actually runs properly on a device I do not know as Android Studio is hanging for the last 20-30 minutes (as it does sometimes). If it does I may answer my own question with what I did to finally fix the problem.
The error shows you that you do not have value white in color constants.
Please check all your resource files (colors.xml, strings.xml and so on) - do you have line
<color name="white">#FFFFFF</color> in one of them?
Try creating a new project entirely, and copy and paste everything. XML files, classes, etc. That should solve your problem.
Eventually solved it by moving (by copying, pasting and deleting since AS wouldn't let me move it) a res directory that had been misplaced from deleting and re-importing the project to try and fix it initially. I don't know which one of the solutions worked but one of them must have. I just had to fix my project again after the re-importing 'solution' broke it. The res directory was a sub-directory of java when it should have been one level up as a sub-directory of main.

R.java file just went missing

I'm working on my app and for this activity I was going to build a new layout file for it. However eclipse gave me an error stating that layout was not updated in the R.java file. So I read online that modifying manifest would update the R.java file but it didn't. So I clicked on clean project and my R.java file disappeared propagating errors across all my src files. Now I heard that it could be due to layouts named with capital letters but all my layouts start with small letters. Also even if I manually add a R.java file and click on clean, the R.java disappears after. I really don't know what to do now. I also tried most of the solutions from the similar questions but to no avail.
Any error on XML files will prevent R generation.
Check for mark errors and Eclipse console (some errors when parsing XML are shown there).
Also I've seen Eclipse generates some dumb files with .out.xml or .xml.out extensions. I'm not sure why it happens, but any "allien" file on res folder also prevents R to be regenerated.
Thanks for your help guys. I tried to look at every file to check for errors but after 30 minutes of scratching my head, I just opened a new project and copied each file to the new project and that is working now.

Categories

Resources