Java 对话框元素初始化错误

Java 对话框元素初始化错误,java,android,listview,dialog,Java,Android,Listview,Dialog,我正在处理一个android项目,现在我的对话框正在工作,我需要使用数组数据在ListView上显示数据,但是当我定义列表视图时,会显示一个错误: 进程:com.example.uhf,PID:31014 java.lang.NullPointerException:尝试调用虚拟方法 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' 关于空对象引用 现在,我认为问题在于查找LV id,因为我使用getVie

我正在处理一个android项目,现在我的对话框正在工作,我需要使用数组数据在
ListView
上显示数据,但是当我定义列表视图时,会显示一个错误:

进程:com.example.uhf,PID:31014

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

'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' 关于空对象引用

现在,我认为问题在于查找LV id,因为我使用getView函数,所以大家可以帮我解决它吗

我的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
ViewGroup viewGroup = getView().findViewById(android.R.id.content);
View dialogView = LayoutInflater.from(v.getContext()).inflate(R.layout.custom_dialog_display_misssing_data, viewGroup, false);
builder.setView(dialogView);
AlertDialog alertDialog = builder.create();
ListView listViewDialog=(ListView)getView().findViewById(R.id.DialogLV);
String[] values = new String[] { "Android List View",
                                 "Adapter implementation",
                                 "Simple List View In Android",
                                 "Create List View Android",
                                 "Android Example",
                                 "List View Source Code",
                                 "List View Array Adapter",
                                 "Android Example List View"
                               };
ArrayAdapter<String> adapterLVDialog = new ArrayAdapter<String>(getContext(),
                                         android.R.layout.simple_list_item_1,
                                         android.R.id.text1, values);                                        
listViewDialog.setAdapter(adapterLVDialog);
alertDialog.show();
AlertDialog.Builder=新建AlertDialog.Builder(getContext());
ViewGroup ViewGroup=getView().findviewbyd(android.R.id.content);
View dialogView=LayoutFlater.from(v.getContext())。充气(R.layout.custom\u dialog\u display\u Missing\u data,viewGroup,false);
builder.setView(dialogView);
AlertDialog AlertDialog=builder.create();
ListView listViewDialog=(ListView)getView().findViewById(R.id.DialogLV);
字符串[]值=新字符串[]{“Android列表视图”,
“适配器实现”,
“Android中的简单列表视图”,
“创建列表视图”,
“Android示例”,
“列表查看源代码”,
“列表视图阵列适配器”,
“Android示例列表视图”
};
ArrayAdapter AdapterVDialog=新的ArrayAdapter(getContext(),
android.R.layout.simple\u list\u item\u 1,
android.R.id.text1,值);
setAdapter(AdapterVDialog);
alertDialog.show();
自定义\u对话框\u显示\u缺少\u data.xml:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="This List containts all missing tags elements"
    android:textAlignment="center"
/>
<ListView
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:id="@+id/DialogLV">
</ListView>

进程:com.example.uhf,PID:31014 java.lang.NullPointerException: 尝试调用虚拟方法“void” android.widget.ListView.setAdapter(android.widget.ListAdapter)“”在 空对象引用

不要

 ListView listViewDialog=(ListView)getView().findViewById(R.id.DialogLV);
Do

 ListView listViewDialog=(ListView)dialogView.findViewById(R.id.DialogLV);