【问题标题】:Android project has lost touch with Resources. Everything seems brokenAndroid 项目与 Resources 失去了联系。一切似乎都破碎了
【发布时间】:2014-08-03 19:32:52
【问题描述】:

我不知道发生了什么,这让我很害怕。

该项目似乎以某种方式脱离了我的资源。如果我更改资源的 ID(R.id.myIdR.id.myId2),项目将继续运行并正常运行,就像 R.id.myId 仍然存在一样。如果我创建一个新字符串 (R.string.newStr),那么我的 java 代码不知道它。它会抱怨资源不存在。

这一切开始时我在做什么?我正在为常见问题解答添加数组资源。我创建了一个新文件my_arrays.xml,如下所示。我放了一些虚拟条目并运行它以确保它有效。它做了。此时,我的 xml 如下所示(我已经重新创建了它)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="faq_questions_array">
        <item>What\'s the news?</item>
        <item>Is this good?</item>
    </string-array>
    <string-array name="faq_answers_array">
        <item>All news is news?</item>
        <item>The best ever</item>
    </string-array>
</resources>

所以我把真正的常见问题解答了。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="faq_questions_array">
        <item>What can this app do?</item>
        <item>How do I add a course?</item>
        <item>Can I edit or remove a course?</item>
        <item>Can I edit/remove/view details of a grade?</item>
        <item>How do I set the current semester?</item>
        <item>How do I account for GPA from previous semesters? Do I have to manually recreate all grades from every course ever? </item>
        <item>Why is a lot of my text red?</item>
        <item>I found a bug. What should I do?</item>
        <item>Do you have any sagely advice for my academic career?</item>
        <item>What is something I should try?</item>
    </string-array>
    <string-array name="faq_answers_array">
        <item>It can track your grades in your classes so that you stay organized and aware in face of slipping scholarships</item>
        <item>There\'s a button. Main screen.</item>
        <item>Well, you probably could if you pressed the menu button while on the course\'s screen.</item>
        <item>Yup. When looking at your grade category (e.g., "Quizzes") tap the grade you want to mess with</item>
        <item>The semester defaults based on the time of year it is and/or isn\'t. You can change it in the settings menu from the home screen.</item>
        <item>Hilariously, yes! Seriously, no. Set your old credit and GPA in the Settings screen.</item>
        <item>Because you're not studying enough.</item>
        <item>It might be carrying diseases. Best kill it. Or email it to me at NSouthProductions@yahoo.com and I\'ll kill it for you.</item>
        <item>Stay on top of your schoolwork. Know when things are due and how much time you'll need to prepare. Go with your gut on a tricky question, but analyze it and follow what's logical. But then remember your gut feeling and let your mind challenge it. Let your gut and mind duke it out and go with either.</item>
        <item>Corn on pizza. They do it in Europe and it is delicious. Add broccoli for real yums. </item>
    </string-array>
</resources> 

我运行了我的应用程序并得到了……这个。它仍在使用旧字符串,即使它们不再存在于我的 xml 中。

现在我发现我的资源似乎完全分离了。我在我的项目中搜索了这些旧字符串,但找不到它们。我已经重新启动了 Eclipse、我的电脑、genymotion 模拟器(并重新安装了它)。无论 XML 文件的内容如何,​​该项目都会继续运行,就好像资源与我完成 FAQ 之前的完全一样。

帮助。

【问题讨论】:

  • 检查你所有的值文件夹。

标签: android eclipse android-layout android-xml android-resources


【解决方案1】:

确保您的 xml 文件没有任何错误,然后执行此操作:

项目 --> 清理 --> 清理所有项目

和:

项目 --> 自动构建

祝你好运

【讨论】:

  • 谢谢,但我仍然收到错误消息。我的 R.txt 文件不见了,重建似乎没有任何作用。
  • 我确定您的 xml 文件有错误,因为当您在 xml 文件中出现错误时,R.java 不会创建检查 res 文件夹中的所有内容。
【解决方案2】:

我以前遇到过这种情况。您需要清理项目并进行重建。

在Eclipse的菜单栏中,找到“Project”,然后依次点击“Clean...”、“Clean all projects”、“OK”。

【讨论】:

  • 嗯,现在我的 java 代码中都有R cannot be resolved to a variable
  • 这很正常。现在单击左侧面板上的项目名称,然后按 F5 刷新。然后进行重建(如果您只是尝试启动应用程序,它可能会自动重建)。
  • 谢谢,但我仍然收到错误消息。我的 R.txt 文件不见了,重建似乎没有任何作用。我无法启动我的项目,因为我现在有 400 个错误。
  • 再一次,这很正常。您可以随时关闭 Eclipse 并重新打开。重启 Eclipse 后,给它几分钟构建和关联,所有 400 错误都会立即消失。
【解决方案3】:
  1. 创建一个新工作区。
  2. 导入您的项目(不含 R.java)。
  3. 转到项目并确保未选中自动构建。
  4. 转到项目并构建它。
  5. R.java 应该会出现。
  6. 您现在可以启用自动构建。

【讨论】:

    猜你喜欢
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2019-02-26
    • 1970-01-01
    相关资源
    最近更新 更多