编译时,Android Manifest导致无法运行的问题?

coolguypie:

我是Android Studio的新手,所以我一直在尝试制作此笔记应用程序。

直到今天早上我不得不做一个菜单来添加笔记时,它的运行情况还是不错的。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/add_note" android:title="Add Note"  ></item>

这样做是为了创建一个菜单,我可以在其中添加注释和内容,但是分别在MainActivity和NoteEditing活动中对其进行引用并进行编译后,它开始起作用。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myjournal">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".NoteEditorActivity"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

具体来说,我没有android:theme =“ @ style / AppTheme”>android:label =“ @ / app_name”,而且我不知道程序从何处获取这些信息。如果我更改这两个并运行,它将崩溃。我将android主题更改为“添加注释”的标题,然后崩溃了

但是,我从未在xml文档中对这两者进行编码,也没有在文件中找到“ styles.xml”。我真的很困惑-修复此问题将不胜感激!编辑:哇!我一直收到的错误是

Android资源链接失败C:\ Users \ mrwad \ AndroidStudioProjects \ MyJournal \ app \ src \ main \ AndroidManifest.xml:5:5-20:19:AAPT:错误:资源样式/ AppTheme(aka com.example.myjournal:style / AppTheme)。

马修·斯特罗姆(Matthew Strom):

嗯,好的,我想我知道发生了什么事。

因此,您说您没有strings.xml,我假设您的styles.xml也未正确设置。

因此,在Android项目中,您应该有一个名为values的目录res

  • 应用-> src-> main /
    • 分辨率/
      • 布局
      • 价值观
        • strings.xml
        • colors.xml
        • styles.xml
      • (您可能拥有的其他资源文件夹)

values目录中包含项目使用的重要资源。这包括字符串,样式,颜色等。

因此,如果您缺少应用程序主题,请确保您的样式中存在主题(错误指向style/AppTheme。这是一个示例styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

这些颜色可以存储在colors.xml

<resources>
    <color name="colorPrimary">#FF0000</color>
    <color name="colorAccent">#00FF00</color>
    <color name="white">#FFFFFF</color>
</resources>

最后,您app_name应该将其驻留在strings.xml文件中:

<resources>
    <string name="app_name">My New App</string>
</resources>

如果缺少这些文件,则只需在中的values目录下创建上述文件app/src/main/res/在开发过程中,您会注意到android不喜欢硬编码的值,并且每当您要编写String或Color等时,它都会提示您在上述文件之一中创建资源条目以供使用。

我强烈建议您阅读一些android文档,它们具有非常冗长的文档集。您可以在此处了解有关资源管理的更多信息

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

编译时,Android Studio中无法删除文件

Android的ORMLite示例无法编译

无法编译为android(Unity)

Android Studio 3.0编译问题(无法在配置之间选择)

由于无法通过编译时验证Android拒绝类

是否是试图编译此代码的错误导致IDE终止或编译器无法运行?

无法编译我的android项目

运行`tns platform add android`时找不到兼容的Android SDK进行编译

编译时无法合并Android清单

使用Lime / OpenFL编译android时出错。无法获取Java版本(Windows 10)

用icc编译时我的程序无法正常运行

在Android Kotlin中,assertNotNull导致单元测试无法运行

两次运行代码时,JPype无法正确编译

编译并运行Android的C代码

无法编译android项目-菜单问题

Swift字典查询导致编译时错误

AWS Android SDK 1.7.1.1无法编译-AmazonHttpClient和HttpClientFactory的问题

使用arm-linux-androideabi-gcc和android ndk编译对象时出现问题

Android Smack MessageEventManager无法编译

Android反编译奇怪的问题

Android源代码编译问题

Android Studio当我按debug时,它将运行测试而不是编译项目

如何构建我的Android Studio项目,以避免在集成了单元测试的情况下运行应用程序而导致编译问题

Angular 2 AoT编译会导致应用程序问题并在JiT中正常运行

编译android源代码时遇到一些问题

BigDecimal 方法调用导致编译时错误

运行项目时缺少 android manifest 中的更改

MLPACK | 编译时问题 | Linux

使用 mui 运行 react app - 编译时出现问题: