Java 在弹出对话框中显示配对蓝牙设备的列表-setAdapter空指针异常
我正在尝试创建一个简单的应用程序,当单击操作栏中的“连接”项时,它会在对话框中显示配对蓝牙设备的列表。下面是我正在膨胀的对话框的XML:Java 在弹出对话框中显示配对蓝牙设备的列表-setAdapter空指针异常,java,android,bluetooth,Java,Android,Bluetooth,我正在尝试创建一个简单的应用程序,当单击操作栏中的“连接”项时,它会在对话框中显示配对蓝牙设备的列表。下面是我正在膨胀的对话框的XML: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/bt_list" android:orientation="vertical" android:layout_width="match_pare
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bt_list"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/BTList"
android:layout_width="fill_parent"
android:layout_height="200dp" >
</ListView>
</LinearLayout>
当我注释掉上面的行时,“连接”按钮会显示一个空白的对话框弹出窗口。我认为崩溃与“BTList”不在当前视图的上下文中有关,但我不确定如何避免它
谢谢您的帮助。您必须从
showBTDialog
中的充气布局ViewLayout
获取列表视图,如下所示:
myListView = (ListView) ViewLayout.findViewById(R.id.BTList);
或者这不是你想做的吗?我明白了。现在这很有道理。非常感谢。
myListView.setAdapter(BTArrayAdapter);
myListView = (ListView) ViewLayout.findViewById(R.id.BTList);