Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在弹出对话框中显示配对蓝牙设备的列表-setAdapter空指针异常_Java_Android_Bluetooth - Fatal编程技术网

Java 在弹出对话框中显示配对蓝牙设备的列表-setAdapter空指针异常

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

我正在尝试创建一个简单的应用程序,当单击操作栏中的“连接”项时,它会在对话框中显示配对蓝牙设备的列表。下面是我正在膨胀的对话框的XML:

<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);