The layout <layout> in layout has no declaration in the base layout folder [error]
AndroidXmlAndroid StudioAndroid Problem Overview
After migrating to Android Studio 3.2, API 28, I am getting the following error on my app's layout:
> The layout
One of the layouts that I am getting this error is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@null" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:adjustViewBounds="true"
android:contentDescription="@string/hello_world"
android:src="@drawable/loading_top" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:adjustViewBounds="true"
android:contentDescription="@string/hello_world"
android:src="@drawable/loading_bottom" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/hello_world"
android:background="@color/white"
android:layout_marginBottom="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:src="@drawable/loading_logo" />
<ImageView
android:id="@+id/loading"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_vertical"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp"
android:contentDescription="@string/hello_world"
android:scaleType="fitXY"
android:src="@null" />
</FrameLayout>
</LinearLayout>
I get the error on the first line of the first LinearLayout.
Does anyone know how to solve this error?
Thank you
UPDATE: Answered my question with what has resolved the problem for me
Android Solutions
Solution 1 - Android
In my case closing and reopening Android studio solved the problem. Rebuilding the project or clearing the cache didn't help.
Solution 2 - Android
Solution 3 - Android
In my case it was the use of capital letters in the file name. I left everything in lowercase and it was fixed.
Solution 4 - Android
If you devise your layout : layout-sw320dp layout-sw480dp layout-sw600dp layout-sw720dp ....
you should add layout by default like this:
Solution 5 - Android
I just did Build > Clean Project
Solution 6 - Android
I received this error when moving layout files between Gradle modules. I didn't have to go so far as to invalidate caches as it resolved itself when I restarted Android Studio
and cleaned the project. It seems likely to be an IDE bug.
Solution 7 - Android
Invalidate Cache / Restart solved my problem.
Solution 8 - Android
In my case i resolved that with this:
the Android say me this id-error:MissingDefaultResource as documentation say:
> If a resource is only defined in folders with qualifiers like -land or > -en, and there is no default declaration in the base folder (layout or values etc), then the app will crash if that resource is accessed on a > device where the device is in a configuration missing the given > qualifier. > > As a special case, drawables do not have to be specified in the base > folder; if there is a match in a density folder (such as > drawable-mdpi) that image will be used and scaled. Note however that > if you only specify a drawable in a folder like drawable-en-hdpi, the > app will crash in non-English locales. > > There may be scenarios where you have a resource, such as a -fr > drawable, which is only referenced from some other resource with the > same qualifiers (such as a -fr style), which itself has safe > fallbacks. However, this still makes it possible for somebody to > accidentally reference the drawable and crash, so it is safer to > create a default dummy fallback in the base folder. Alternatively, you > can suppress the issue by adding tools:ignore="MissingDefaultResource" > on the element. > > (This scenario frequently happens with string translations, where you > might delete code and the corresponding resources, but forget to > delete a translation. There is a dedicated issue id for that scenario, > with the id ExtraTranslation.)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingDefaultResource" <!--this-->
android:layout_width="match_parent"
android:layout_height="match_parent">
But this is the easy solution, 'cause you make missing the resourse in Android.
I resolve this with file system option. If Android tell you about missing resourse meaning some thing is missing and you should replenish that.
you should be go to
maybe: right click in file's missing folder, show in Exporer,and go back to
You should be find
/layout
/layout-normal
/layout-large
/some more folders
You should be find where do the files is missing. In my case that's missing in /layout
Solution 9 - Android
In my case, this issue was caused by Uppercase letter. Wrong chars like "-" can also cause the issue.
I changed the name from Activity_disease.xml
to activity_disease.xml
and the issue fixed.
Solution 10 - Android
Nothing worked for me like rebuilding the project or Invalidating the cache. In my case closing and reopening Android studio solved the problem.
Solution 11 - Android
Press- 'ctrl+A' --> 'ctrl+x' --> 'ctrl+v') this does not change anything but apparently solves the errors.
Solution 12 - Android
I solved this issue by just syncing project with gradle
Solution 13 - Android
I had copied the xml files in the folder using Windows Explorer. It seems to have caused an encoding issue. After deleting the files and coping them inside Android Studio, the problem was resolved.
Solution 14 - Android
In my case it seems that Google used to expect (or at least accept) different names between different layouts; I had a time_dialog.xml
and a time_dialog_landscape.xml
. Renaming the latter to time_dialog.xml
fixed the problem.
Solution 15 - Android
For me the following steps made it work:
- Cut all the code out of the page (ctrl+A+X for windows)
- Paste the code back.
Solution 16 - Android
I had an issue after copy/pasting code into an XML layout file, but I fixed it by just manually creating the file. Very strange, since the code was exactly the same, but somehow it fixed this issue. I did try restarting and doing the "File => Invalidate Caches / Restart => Invalidate and Restart" fix, but the issue was only fixed by manually recreating the file.
Solution 17 - Android
Note that when you are using different versions of layout like (Large/Small/Nornal) then that case you have to same main layout folder. like this way
Solution 18 - Android
Similarly to the previous post, I had to rename the resource. I created it initially by copy-pasting an .xml
file in the project explorer. Confusingly this had the same name in the explorer but with a land
dimmed attribute associated with the layout.
My solution was to go into the file system and manually move the file from the layout-land
to layout
folder
Solution 19 - Android
For me it occured because I had accidentally named the file with a spacebar rather than underline, i.e fragment_item summary.xml
rather than fragment_item_summary.xml
.
Solution 20 - Android
This issue seems to be happening because studio or compiler is not able to find the resource file inside the base layout folder. To solve the problem you might need to create the file into different layout folders. If you are using layout folders v21, v25 etc. folders for designing layouts for different target devices then you also might need to place your resource files there too.
Solution 21 - Android
In my case this warning appeared due to "wrong" character (dot) used in value name:
<dimen name="dp.divider.xlarge">24dp</dimen>
Removing dots (right click on a name, then Refactor-Rename in Android Studio) resolved the problem.
Solution 22 - Android
Late to the party but My case is different from above.
I just renamed the resource and it started working.
Actually my resource name was ic_menu_black_24dp.xml so it was conflicting with the android's menu resource.
Solution 23 - Android
What worked for me is to remove the id attribute
android:id="@+id/[id same as filename]"
from the layout resource.
Solution 24 - Android
Solution 25 - Android
What solved it for me:
In Android Studio, right-click on the filename in the layout directory, and choose Reformat code, with no special tickbox selected on the next screen.
Not sure what exactly goes on under the hood here, but that worked.
Solution 26 - Android
In my case the same error was showing because layout-land file and layout filename was different.
My Case: layout-land -> my_layout_land layout -> my_layout
I solved it by making both filenames the same. Because if you are using layout-land and you have a file in layout-land then you must have a file in layout folder also.
Solution 27 - Android
Placing tools:ignore="MissingDefaultResource"
in the screen layout description solved it for me.