ListView.setAdapter(ArrayAdapter) is crashing app

时间:2017-08-30 20:22:44

标签: java android listview bluetooth

I am trying to populate a listView with paired bluetooth devices. I tried doing so with a ListView in my MainActivity and it worked perfectly. However, when I tried it with a ListView in a different activity it crashed the app. I basically want to populate a ListView in a pop-up dialog box.

Here is the code:

activity_device_list.xml (MainActivity)

  deactivate(){
    this.controller.reset();
  }

device_dialog.xml

deactivate

DeviceList.java

KafkaIO

If I change <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="1"> <ListView android:id="@+id/listDevicesMain" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> to <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.12" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="Paired Devices" android:textSize="25sp" /> <ListView android:id="@+id/listDevicesDialog" android:layout_width="match_parent" android:layout_height="395dp" android:layout_weight="0.38" /> </LinearLayout> the code works perfectly fine.

2 个答案:

答案 0 :(得分:1)

you calling the wrong list view the id of the list view as you have given is

n

and you are trying to call the listview with id random_permute_generator(iterable, n=5000) hope this will solve the issue.

答案 1 :(得分:0)

data: { hashtags: [] }, methods: { filterHashtags() { // commented out stuff // set the data property with the filtered values this.hashtags = fHashtags; } }, created(){ this.filterHashtags(); } - here you are looking for <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Art</a> <ul class="dropdown-menu" role="menu"> <li><a href="UploadArt.aspx">Upload Art</a></li> <li><a href="SearchForArt.aspx">Search For Art</a></li> </ul> </li> in activity layout, so <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <link href="Styles/css/bootstrap.min.css" rel="stylesheet"> <link href="Styles/css/NewStrap.css" rel="Stylesheet" /> <script src="Styles/js/bootstrap.min.js"></script> becomes null. You should add devicelist = (ListView)findViewById(R.id.listDevicesDialog); to showDialog() method and bring there rest of the operations related with searching for paired devices and setting adapter.

You can also call pairedDevicesList from showDialog and pass view where listDevicesDialog is:

listDevicesDialog