2011-07-21 48 views
1

我正在關注一本書以學習Android,並且出現錯誤,這是我的代碼code with errorAndroid:(簡單)缺少導入或...?

我正在使用上面的圖片,因此您也可以看到錯誤(複合按鈕)。

我輸入了錯誤的內容還是本書沒有寫入一些所需的輸入?

謝謝!

EDITED全碼:

package newbook.appress; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 

public class CheckBoxDemo extends Activity 
implements CompoundButton.OnCheckChangedListener{ 

    CheckBox cb; 

    @Override 
     public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main); 

     cb=(CheckBox)findViewById(R.id.chkBox1); 
     cb.setOnCheckedChangeListener(this); 
    } 


    public void onCheckedChanged(CompoundButton buttonView, 
      boolean isChecked) { 
     if (isChecked) { 
     cb.setText("This checkbox is: checked"); 
     } 
     else { 
     cb.setText("This checkbox is: unchecked"); 
     } 
     } 

} 
+0

我假設這是日食,這是什麼,當你將鼠標懸停在紅色部分的錯誤說? – Albinoswordfish

+0

是的,「compoundButton不能解析爲類型」 – Ryan

回答

2

這是正確的。你需要導入一切。這是因爲丟失:

import android.widget.CompoundButton 

您可以鍵入:

按Ctrl + ØØ在Eclipse中自動rganize的進口。

您還需要第二個錯誤更改爲:

cb.setOnCheckedChangeListener(this); 
+0

好吧,這樣做,它將CompoundButton添加到導入列表,但它仍然有錯誤,它說「CompoundButton.OnCheckChangedListener不能解析爲類型」 – Ryan

+2

Ryan,正確類名是CompoundButton.OnCheckedChangeListener,而不是CompoundButton.OnCheckChangeListener :) – Shlublu

+0

啊謝謝!有點混淆了!新手錯誤:)) – Ryan