###前提・実現したいこと
初歩的なことですみません。
大津真さんの「JavaからはじめようAndroidプログラミング」で勉強中で、そのコードのとおりにしているのですが、どうしてもエラーが出てきます。
下記のとおり、menuあるいはmenu_mainとaction_settingsのエラーです。
###発生している問題・エラーメッセージ
MainActivity.javaのところで、
エラー:シンボルを見つけられません
シンボル: 変数menu
場所: クラスR
エラー:シンボルを見つけられません
シンボル: 変数action_settings
場所: クラスid
というエラーが出力されます。
あと、続けてこの様な出力があります。
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
###該当のソースコード
MainActivity.javaの該当部分のみです。
@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); }
###試したこと
初心者ですのでGoogleで調べましたが、日本語でのヒットはなく、英語でのヒットがいくつかあったのみです。
そこで、一番分かりやすそうなものを見つけて、menu.menu_mainにカーソルを当てた状態で、alt+enterを押して、resの中にmenu_main.xmlを作成し、
R.javaは変更しない方がいいと本には書かれていましたが、Rのidの中に
public static final int action_settings = 0;
という一か八か書いたりしましたが、ダメでした。
そうすると、MainActivity.javaのR自体が赤字になる始末です。
要するに、action_settingsというのと、menu_mainというものが定義されていないということだとは思うのですが、素人で歯が立たない次第です。
よろしくお願いします。
###補足情報(言語/FW/ツール等のバージョンなど)
android studio 2.2.3
回答1件
あなたの回答
tips
プレビュー