无法解析符号'R',&无法解析menu_main xml中的符号

时间:2015-11-13 03:05:06

标签: java android xml

我在这里很沮丧。我在这里搜索并尝试了很多不同的东西。我刚刚开始这个项目,我试图首先在3dot菜单中添加选项。继承我的menu_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">


    <item android:id="@id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never" />
    <item android:id="@id/opt1" android:title="@string/opt1" android:onClick="onOption1" android:showAsAction="ifRoom|withText" />
    <item android:id="@id/opt2" android:title="@string/opt2" android:onClick="onOption2" android:showAsAction="ifRoom|withText" />
    <item android:id="@id/opt3" android:title="@string/opt3" android:onClick="onOption3" android:showAsAction="never" />
    <item android:id="@id/opt4" android:title="@string/opt4" android:onClick="onOption4" android:showAsAction="never" />
    <item android:id="@id/opt5" android:title="@string/opt5" android:onClick="onOption5" android:showAsAction="never" />
    <item android:id="@id/opt6" android:title="@string/opt6" android:onClick="onOption6" android:showAsAction="never" />
    <item android:id="@id/opt7" android:title="@string/opt7" android:onClick="onOption7" android:showAsAction="never" />
    <item android:id="@id/opt8" android:title="@string/opt8" android:onClick="onOption8" android:showAsAction="never" />
    <item android:id="@id/opt9" android:title="@string/opt9" android:onClick="onOption9" android:showAsAction="never" />
    <item android:id="@id/opt10" android:title="@string/opt10" android:onClick="onOption10" android:showAsAction="never" />
</menu>

的strings.xml:

<resources>
    <string name="app_name">Watchproj</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>

    <string name="opt1">Display list forward</string>
    <string name="opt2">Display list backwards</string>
    <string name="opt3">Add new watch</string>
    <string name="opt4">Show details of watch</string>
    <string name="opt5">Delete watch</string>
    <string name="opt6">Show average price</string>
    <string name="opt7">Show number of automatic watches</string>
    <string name="opt8">Show most expensive watch</string>
    <string name="opt9">Load list from file</string>
    <string name="opt10">Save list from file</string>
</resources>

Mainactivity.java

package com.example.annon.watchproj;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    public void onOption1(MenuItem i){

    }
    public void onOption2 (MenuItem i){

    }
    public void onOption3 (MenuItem i){

    }
    public void onOption4 (MenuItem i){

    }
    public void onOption5 (MenuItem i){

    }
    public void onOption6 (MenuItem i){

    }
    public void onOption7 (MenuItem i){

    }
    public void onOption8 (MenuItem i){

    }
    public void onOption9 (MenuItem i){

    }
    public void onOption10 (MenuItem i){

    }

}

我不知道该怎么做,我只是希望我错过了一些愚蠢的事情。我清理了项目,并重建了几十次。我只是试图运行它,看看我是否可以选择显示。

1 个答案:

答案 0 :(得分:2)

id应该是这样的

@+id/action_settings

你的(没有+)

@id/action_settings