简体   繁体   English

Android:R.java:错误 <identifier> 预期

[英]Android: R.java: error <identifier> expected

I am a beginner to android development, and was following the training guide at developer.android.com (Better tutorials would be greatly appreciated as well). 我是android开发的初学者,并且正在关注developer.android.com上的培训指南(更好的教程也将受到高度赞赏)。 I was adding the action bar when I started getting this error. 当我开始收到此错误时,我正在添加操作栏。

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

It also says 它还说

error:  <identifier> expected

The main problem I am having is that R.java is generated by android studio and I have never touched it so I am very confused. 我遇到的主要问题是R.java是由android studio生成的,我从未触及过它,所以我很困惑。

The actual R.java code is here. 实际的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;
}

The error is thrown on the first line of the function at the =action_settings part. 错误在= action_settings部分的函数的第一行抛出。

Any help at all would be greatly appreciated. 任何帮助都将非常感激。 Also if there is anything else you need to see please let me know. 如果还有什么需要看的话请告诉我。 I'm still getting used to android and android studio so I am still not sure where everything is to help debug. 我仍然习惯了android和android studio所以我仍然不确定一切都是为了帮助调试。

It sounds like you have accidentally defined a menu item in your XML with an id of =action_setting . 听起来你不小心在XML中定义了一个id为=action_setting的菜单项。

For example: 例如:

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

Remove the = from your menu XML and you should be good to go. 从你的菜单XML中删除=你应该很高兴。

I had the same problem, because I defined a string without name in my resources. 我有同样的问题,因为我在我的资源中定义了一个没有名字的字符串。 like: 喜欢:

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

check your resource file name should be following file naming rule. 检查您的资源文件名应该遵循文件命名规则。 Example: 例:

Invalid file name: 50x60.png Valid file name: my_pic.png 文件名无效:50x60.png有效文件名:my_pic.png

I had similar problem. 我有类似的问题。 Step 1. Delete/edit files which caused error, in your case: "public static final int =action_settings=0x7f050018;" 步骤1.在您的情况下删除/编辑导致错误的文件:“public static final int = action_settings = 0x7f050018;”

Step 2. Build->Clear. 第2步。构建 - >清除。 Since R.java cant be modified and automatically generated, dont edit anything in R.java. 由于R.java无法修改并自动生成,因此不要在R.java中编辑任何内容。 Good luck! 祝好运! :) :)

I encountered the same error message. 我遇到了同样的错误消息。 In my case it seemed to be caused by the inclusion of '.int' in the package name. 在我的情况下,它似乎是由包名中包含'.int'引起的。

Replacing '.int' in the package name: 替换包名称中的'.int':

com.xxxx.int.yyyy

With '.intg' resolved the error for me: 使用'.intg'为我解决了错误:

com.xxxx.intg.yyyy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM