Java 我正在尝试将内容作为字符串放入ListView
我试图将内容作为字符串放入ListView。运行代码后,ListView的对象包含null。我不确定问题出在哪里?请帮忙!!不要忘记,employee将其作为位于TabLayout中的Tap类的对象Java 我正在尝试将内容作为字符串放入ListView,java,Java,我试图将内容作为字符串放入ListView。运行代码后,ListView的对象包含null。我不确定问题出在哪里?请帮忙!!不要忘记,employee将其作为位于TabLayout中的Tap类的对象 //Step 1. Create and initialize the array. String[] temp = {"Book", "Notebook", "pen", "pencil"}; //Step 2. Convert the array to ObservablList Observ
//Step 1. Create and initialize the array.
String[] temp = {"Book", "Notebook", "pen", "pencil"};
//Step 2. Convert the array to ObservablList
ObservableList<String> strList = FXCollections.observableArrayList(temp);
//Step 3. Convert the ObservableList to ListView
ListView<String> listView = new ListView<>(strList);
//Step 4. Add the content of ListView to the employee Tap.
employee.setContent(listView);
//第1步。创建并初始化数组。
String[]temp={“Book”、“Notebook”、“pen”、“pencil”};
//第二步。将数组转换为可观察列表
ObservableList strList=FXCollections.observableArrayList(临时);
//第三步。将ObservableList转换为ListView
ListView ListView=新的ListView(strList);
//第四步。将ListView的内容添加到员工点击。
employee.setContent(listView);
执行步骤4时,将抛出except。我认为这是因为第三步。ListView元素的对象为空 亲爱的,你想错了
listView.getItems().add(list)
其中list是一个列表
或可观察列表
。另外,您不能将可观察列表
转换为列表视图,
列表视图
是一个视图
,您可以在UI上看到。如果您可以向我们展示stacktrace,我们可以为您提供更多帮助。代码正是本书解释问题的方式(在ListView中显示字符串数组的元素)。在listview中导入数组元素还有其他方法吗?