【问题标题】:Android: R.java: error <identifier> expectedAndroid:R.java:错误 <标识符> 预期
【发布时间】:2014-09-08 19:33:19
【问题描述】:

我是 android 开发的初学者,并且正在学习 developer.android.com 上的培训指南(我们也将不胜感激更好的教程)。当我开始收到此错误时,我正在添加操作栏。

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:app:preBuild
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportSupportV132000Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42000Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWearable5077Library UP-TO-DATE
:app:prepareComGoogleAndroidSupportWearable100Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava
C:\Users\Brian\AndroidStudioProjects\MyAndroidWear\app\build\generated\source\r\debug\com\example\brian\myandroidwear\R.java:400: error: <identifier> expected
    public static final int =action_settings=0x7f050018;
                           ^
1 error

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.271 secs

它也说

error:  <identifier> expected

我遇到的主要问题是R.java是由android studio生成的,我从来没有接触过它,所以我很困惑。

实际的 R.java 代码在这里。

 public static final class id {
    public static final int =action_settings=0x7f050018;
    public static final int action_error=0x7f05000b;
    public static final int action_search=0x7f050017;
    public static final int action_settings=0x7f050016;
    public static final int action_success=0x7f05000d;
    public static final int all=0x7f050004;
    public static final int animation=0x7f05000e;
    public static final int bottom=0x7f050003;
    public static final int button_send=0x7f050014;
    public static final int dismiss_overlay_button=0x7f050011;
    public static final int dismiss_overlay_explain=0x7f050010;
    public static final int edit_message=0x7f050013;
    public static final int error_message=0x7f05000c;
    public static final int hybrid=0x7f050009;
    public static final int left=0x7f050000;
    public static final int message=0x7f05000f;
    public static final int none=0x7f050005;
    public static final int normal=0x7f050006;
    public static final int right=0x7f050002;
    public static final int satellite=0x7f050007;
    public static final int terrain=0x7f050008;
    public static final int text=0x7f050012;
    public static final int title=0x7f050015;
    public static final int top=0x7f050001;
    public static final int watch_view_stub=0x7f05000a;
}

在=action_settings部分函数的第一行抛出错误。

任何帮助都将不胜感激。另外,如果您还有什么需要看的,请告诉我。我还在习惯 android 和 android studio,所以我仍然不确定一切都可以帮助调试。

【问题讨论】:

  • 错字:删除action_settings之前的=。而且那个变量似乎是重复的......
  • 去掉public static final int =action_settings=0x7f050018;应该是public static final int action_settings=0x7f050018;

标签: java android identifier


【解决方案1】:

听起来您不小心在 XML 中定义了一个 ID 为 =action_setting 的菜单项。

例如:

<menu>
    <item 
        android:id="@+id/=action_settings" />
</menu>

从您的菜单 XML 中删除 =,您应该一切顺利。

【讨论】:

  • 谢谢你,如果没有你的帮助,我会一直坚持下去 :)
【解决方案2】:

我遇到了同样的问题,因为我在资源中定义了一个没有名称的字符串。 喜欢:

<string name="">some text</string>

【讨论】:

    【解决方案3】:

    检查您的资源文件名是否应遵循文件命名规则。 示例:

    文件名无效:50x60.png 有效文件名:my_pic.png

    【讨论】:

      【解决方案4】:

      我遇到了同样的错误信息。就我而言,这似乎是由于包名称中包含“.int”引起的。

      替换包名中的“.int”:

      com.xxxx.int.yyyy
      

      使用 '.intg' 为我解决了错误:

      com.xxxx.intg.yyyy
      

      【讨论】:

        【解决方案5】:

        我有类似的问题。 第 1 步。删除/编辑导致错误的文件,在您的情况下:“public static final int =action_settings=0x7f050018;”

        第 2 步。构建->清除。由于 R.java 不能被修改和自动生成,所以不要在 R.java 中编辑任何东西。 祝你好运! :)

        【讨论】:

          猜你喜欢
          • 2022-07-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多