2016-05-19 87 views
2

我不斷收到錯誤消息:錯誤:無法找到符號變量action_settings

"cannot find symbol variable action_settings"

我該如何解決這個問題?

我得到一個類似的錯誤mesaage對此部分:

.inflate(R.menu.menu_main, menu); 

後來我跟着從別人放在這裏的建議關於在res文件中添加菜單文件。

我該怎麼處理這種情況?

package com.example.android.courtcounter; 
 

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

 
/** 
 
* This activity keeps track of the basketball score for 2 teams. 
 
*/ 
 
public class MainActivity extends AppCompatActivity { 
 

 
    // Tracks the score for Team A 
 
    int scoreTeamA = 0; 
 

 
    // Tracks the score for Team B 
 
    int scoreTeamB = 0; 
 

 
    
 
    @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 SimpSlifiableIfStatement 
 
     if (id == R.id.action_settings) { 
 
      return true; 
 
     } 
 

 
    } 
 
}

+0

進口R.id.action_settings?或者申報。 – markspace

+0

我們需要查看「main_menu」聲明的XML資源來驗證您的語句並創建action_settings菜單選項 – JCricket

回答

0

你的菜單menu_main應包含一定的視圖(ID = action_settings)。或者你只是刪除線

if (id == R.id.action_settings) 
相關問題