2016-12-15 81 views
0

我一直在試圖讓這個小代碼工作我得到更遠,因爲我跳過它,但需要回到它我的buttonPlay沒有被識別,我的書告訴我我需要導入指令。我怎麼這個符號不被識別按鈕顯示

//這是切入點,我們的遊戲

@Override 
protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
    // Here we set our UI layout as the view 
    setContentView(R.layout.activity_main); 
    // Get a reference to the button in our layout 
    final Button buttonPlay = (Button) findViewById(R.id.buttonPlay); 
    buttonPlay.setOnClickListener(this); 

回答

0

我假定你正在談論這一行:

final Button buttonPlay = (Button) findViewById(R.id.buttonPlay); 

編譯器抱怨這個部分: R.id.buttonPlay。這是說使用buttonPlay是一個未定義的符號。

R類實際上是從包含您的應用程序的UI設計的XML文件自動生成的。它包括各種元素的名稱。編譯錯誤的最可能的解釋是,「buttonPlay」在XML中沒有被定義,或者你刪除了它,或者你沒有在兩個地方拼寫相同的名字(包括大寫字母)。

+0

好的,生病試試,謝謝你的擡頭 –

+0

是的,這對我已經工作了謝謝你的幫助抱歉,回覆晚了 –