java - 无法解析字符串符号AndroidManifest.xml

标签 java android

我正在使用本教程创建一个天气应用程序: https://blog.teamtreehouse.com/beginners-guide-location-android 我注意到由于某种原因我收到了错误:“无法解析符号“R””和“无法解析符号“setUpMapIfNeeded()”。这些是我已经尝试过的所有事情: 清理/构建项目,文件>无效缓存/重新启动..,删除构建文件夹,首先同步Gradle,在settings.gradle中添加“include':app'”,甚至导入.R,我在导入时遇到相同的错误.. 。 最终,我发现我的一个 .xml 文件可能有问题。

事实证明,在我的 AndroidManifest.xml 文件中的元数据部分,android:value="@string/google_maps_key"/> 颜色为红色,并且它还显示“无法解析符号”。

这是完整的 list 代码:

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

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

    <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key"/>

    <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

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

google_maps_key 只是用于访问天气数据的 API key 。实际的 key 位于 google_maps_api.xml 中,这是其中的所有代码:

<resources>
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">YOUR_KEY_HERE</string>
</resources>

我仍然不明白为什么谷歌地图键字符串不能像其他两个符号一样被解析。我不知道还能做什么,我已经尝试了一切。下面也是主类的截图:

enter image description here

最佳答案

字符串资源错误。您粘贴错误,名称必须为 name="google_maps_key"

<resources>
  <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">AIzaSyDtyUdRtbkQ3GqpXaT_......</string>
</resources>

关于java - 无法解析字符串符号AndroidManifest.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52610506/

相关文章:

java - 想要一个带有透明背景图像的 JLabel

java - 在 64 位 Linux 服务器上运行 64 位 JVM 的优点/缺点?

java - 如何设置这个 View ?

android - Activity 未延伸到横向切口下方

java - Android 中的自定义 View 在每个设备上看起来都不同

java - 使用 InjectionPoint 在注入(inject)和检索时传递参数

java - Java中的十六进制转十进制

java - 如何在单个帖子中发送文件和数据?

android - 壁纸应该每天在Android手机上自动更换

android - 如何发送到 "Miscellaneous"通知 channel ?