-1
我想要插入圖像到linearlayout這是在dialog.But內運行應用程序時,我得到了空指針異常錯誤。 我想知道如何獲取對話框中的視圖對象。引起︰java.lang.NullPointerException︰嘗試調用虛擬方法
這裏是我的代碼裏面的oncreate函數。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compinfo);
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_compinfopopup);
dialog.getWindow().getAttributes().width = AbsListView.LayoutParams.MATCH_PARENT;
dialog.getWindow().getAttributes().height = AbsListView.LayoutParams.WRAP_CONTENT;
dialog.show();
myGallery = (LinearLayout) findViewById(R.id.mygallery);
myGallery.addView(insertPhoto("http://www.a.com/demos/img/home/01.jpg"));
myGallery.addView(insertPhoto("http://www.a.com/demos/img/home/02.jpg"));
myGallery.addView(insertPhoto("http://www.a.com/demos/img/home/02.jpg"));
myGallery.addView(insertPhoto("http://www.a.com/demos/img/home/02.jpg"));
}
請幫
你想添加這些imageView到你的對話框? –
你可以發佈你的XML嗎? –
是的我想將圖像添加到對話框內的線性佈局 – Ashish