1
我有以下代碼:的Android setImageResource NullPointerException異常
public class PainLogger extends Activity implements OnClickListener, OnItemClickListener{
ImageView image;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.imageView1);
image.setImageResource(R.drawable.acetaminophen); //**Null Pointer Here**
....
}
}
這裏是在items.xml文件中的圖像。 (我認爲這是爲什麼它是空的 - 而不是在main.xml文件中,imageView在我的items.xml文件中,雖然它在R.id和R.drawable中顯示)
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content"
android:src="@drawable/icon" android:id="@+id/imageView1"></ImageView>
感謝,但我不知道如何將我的main.xml文件中的圖像視圖。做我只是說「<包括ImageView的機器人:layout_height =‘包裝...............> />’ – Kgrover
你可以只複製/在粘貼布局 – Gregory
哦確定? ,但這是我的目標是在我的應用程序中執行操作:我在主佈局中有一個列表,當單擊時,我想要顯示此佈局,「item.xml」,它應該有一個imageview在其中...所以我將如何從我的PainLogger.java文件中執行此操作? – Kgrover