Android 原因:java.lang.NullPointerException:尝试调用虚拟方法

Android 原因:java.lang.NullPointerException:尝试调用虚拟方法,android,image,dialog,Android,Image,Dialog,我正在尝试将图像插入到对话框中的linearlayout中。但在运行应用程序时,我收到nullpointer异常错误。 我想知道如何在对话框中获取视图对象 这是我在oncreate函数中的代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compinfo); dialog =

我正在尝试将图像插入到对话框中的linearlayout中。但在运行应用程序时,我收到nullpointer异常错误。 我想知道如何在对话框中获取视图对象

这是我在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"));
}

请帮助

myGallery=(LinearLayout)对话框

是否要将这些图像视图添加到对话框中?是否可以发布xml?是的,我要将图像添加到对话框中的线性布局中