Android开发者MyFirstApp - "菜单不能得到解决或不是场" [英] Android Developers MyFirstApp - "menu cannot be resolved or is not a field"

查看:96
本文介绍了Android开发者MyFirstApp - "菜单不能得到解决或不是场"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用在机器人提供的教程构建我的第一个应用程序月食。

I am attempting to build my first app using the tutorial provided by android in Eclipse.

我所做的一切是说,但我得到的错误信息...菜单不能得到解决或不是场。本教程中没有提到有关菜单的任​​何事情,我敢肯定,我还没有给它做任何事情。它是在抱怨我行已标记的评论。

I've done everything is says but i get the error message..."menu cannot be resolved or is not a field". The tutorial doesn't mention anything about a menu and i'm sure i haven't done anything to it. The line it is complaining about i've marked in a comment.

package com.example.my.first.app;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);        <!--this line-->
    return true;
}
}

这是主要的活动页面的教程要我修改如下所示...

This is the main activity page the tutorial has asked me to edit is shown below...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText android:id="@+id/edit_message"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send" />
</LinearLayout>

去关闭的意见,我已经在其他问题中我已经尝试点击它,包括什么都它的要求是在类型创建领域菜单R或类型创建常量'菜单' R。我已经单独进行两个和我每次保存项目,因此重建后,它会自动删除被列入该行。

Going off advice i've found on other questions i've attempted clicking on it and to include what ever it's asking for which is "Create field 'menu' in type 'R' or "Create constant 'menu' in type 'R'. I've done both separately and every time i save the project so it rebuilds, it automatically deletes the line that was included.

有关的领域,这样做。 - 公共静态对象菜单; 对于恒定的,这样做。 - 公共静态最后弦乐菜单= NULL;

For the field, this was done. - public static Object menu; For the constant, this was done. - public static final String menu = null;

所以,我现在有点卡住,想一些急需的帮助,请。

So i'm now a little stuck and would like some much needed help please.

推荐答案

该onCreateOptionsMenu方法,是指具有在/ RES /菜单文件夹中,实现为XML的菜单。看起来是这样的:

The onCreateOptionsMenu method refers to a menu that has to be in /res/menu folder and is implemented as XML. Looks like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
    android:title="@string/menu_settings"
    android:orderInCategory="100" />
</menu>

您可以复制/粘贴此code,将其保存为activity_main.xml在你的/ RES /菜单文件夹(创建一个,如果你没有一个)或直接删除整个方法

You can copy/ paste this code, save it as activity_main.xml in your /res/menu folder (create one if you dont have one) or just delete the whole method

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);        <!--this line-->
    return true;
}

这样做是打开一个菜单,当你到了设备上的菜单按钮,如果你删除的方法,你不会有这样的菜单。如果你需要一个你仍然可以创建一个。

What this does is open a menu when you hit the menu button on the device, if you delete the method, you wont have such a menu. You can still create one if you need one.

这篇关于Android开发者MyFirstApp - &QUOT;菜单不能得到解决或不是场&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆