我有一个自定义对话框,我将其设置为一个函数:
public void customDialog(Bitmap bm,String title){
TextView dialogtext = (TextView)findViewById(R.id.layout_root);
//For above also tried r.id.popup which is the containing file for the layout
ImageView dialogimage = (ImageView)findViewById(R.id.popupimage);
dialogtext.setText(title);
dialogimage.setImageBitmap(bm);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.popup,(ViewGroup) findViewById(R.id.layout_root));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.show();
}
每当我尝试使用Null指针异常动态设置XML字段时,对话框都会失败.我很难过,有什么想法吗?我是否必须在清单中添加一些自定义对话框?
作者分享了在Android应用中创建自定义对话框时遇到的Null Pointer异常问题,尤其是在尝试动态设置XML视图时。寻求解决方案,可能涉及到LayoutInflater、XML文件引用和正确初始化关键视图。
990

被折叠的 条评论
为什么被折叠?



