L K*_*emp 61 xml android android-studio
从Eclipse迁移到新版本的Android Studio 3.2,API 28后,我的应用程序布局出现以下错误:
布局中的布局在基本布局文件夹中没有声明; 在与此限定符不匹配的配置中查询资源时,这可能导致崩溃
我收到此错误的布局之一是:
<?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>
Run Code Online (Sandbox Code Playgroud)
我在第一个LinearLayout的第一行得到错误.
有谁知道如何解决这个错误?
谢谢
更新:这似乎是一个编码问题.我使用Windows资源管理器复制了文件夹中的xml文件.删除文件并在Android Studio中处理它们后,问题已经解决.
vov*_*ost 69
在我的情况下,关闭和重新开放Android工作室解决了这个问题.重建项目或使缓存无效没有帮助.
Ito*_*oun 30
你也可以试试这个:
File => Invalidate Caches/Restart => Invalidate和Restart.
小智 6
就我而言,我解决了这个问题:
Android 告诉我这个id-error: MissingDefaultResource作为文档说:
如果资源仅在带有 -land 或 -en 等限定符的文件夹中定义,并且基本文件夹(布局或值等)中没有默认声明,则如果在设备所在的设备上访问该资源,则应用程序将崩溃处于缺少给定限定符的配置中。
作为一种特殊情况,不必在基本文件夹中指定可绘制对象;如果密度文件夹(例如 drawable-mdpi)中存在匹配项,则将使用并缩放该图像。但是请注意,如果您只在像 drawable-en-hdpi 这样的文件夹中指定可绘制对象,则应用程序将在非英语语言环境中崩溃。
在某些情况下,您可能拥有一个资源,例如 -fr drawable,它仅从具有相同限定符(例如 -fr 样式)的其他资源中引用,而该资源本身具有安全回退。但是,这仍然可能让某人意外引用可绘制对象并导致崩溃,因此在基本文件夹中创建默认的虚拟回退更安全。或者,您可以通过在元素上添加 tools:ignore="MissingDefaultResource" 来抑制该问题。
(这种情况经常发生在字符串翻译中,您可能会删除代码和相应的资源,但忘记删除翻译。该场景有一个专用的问题 ID,其 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">
Run Code Online (Sandbox Code Playgroud)
但这是一个简单的解决方案,因为你会错过 Android 中的资源。
我用文件系统选项解决了这个问题。如果Android告诉您缺少资源意味着缺少某些东西,您应该补充它。
你应该去\app\src\main\res
也许:右键单击文件丢失的文件夹,在Exporer中显示,然后返回\app\src\main\res
你应该找到
/layout
/layout-normal
/layout-large
/some more folders
Run Code Online (Sandbox Code Playgroud)
您应该找到文件丢失的位置。在我的情况下, /layout 中缺少
归档时间: |
|
查看次数: |
26893 次 |
最近记录: |