下面的代碼給了我一個錯誤這段代碼爲什麼給我一個錯誤?
public class SuperImage3Activity extends Activity
{
ImageView image1, image2;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image1 = (ImageView)findViewById(R.drawable.sourceimage1); // error here
image2 = (ImageView)findViewById(R.drawable.sourceimage2); // error here
}
我的確創建了一個名爲繪製和放置sourceimage1.jpg和sourceimage2.jpg目錄中的目錄。
通過Eclipse中給出的建議是,
「作爲ADT 14時,資源領域(如哆啦A夢)不再常量庫中的對象定義時, 這是必要的,使庫項目可重複使用而無需重新編譯它們。這一
一個後果是,你不能再在switch語句中使用的字段directinly。 您必須使用的if-else鏈,而不是 「
findViewyId表示XML佈局中的控件ID,因此您必須給出控件的標識而不是它的iamge資源。謝謝 – SALMAN
http://www.higherpass.com/Android/Tutorials/Working-With-Images-In-Android/你可以看看這個例子 – SALMAN
而不是評論你自己的答案,考慮修改答案主體。 –