【发布时间】:2023-03-25 22:24:02
【问题描述】:
我正在尝试从服务器获取菜单项的 json 列表,对其进行解析,并将其显示在片段视图中。完整代码在这里:http://pastebin.com/8UEgcyfa
在添加获取 json 和解析的代码之前,该应用只是显示来自字符串资源的硬编码菜单项列表,如下所示:
String[] adobe_products = getResources().getStringArray(R.array.adobe_products);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.fragment_viewdishes, R.id.label, adobe_products));
这工作正常。在尝试实际打印解析后收到的菜单项时,我在 onPostExecute 方法中执行了此操作(请参阅完整代码),其中 menuNameArray,(我认为)正确保存了我实际需要在 ListView 上显示的菜单项数组:
this.setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.fragment_viewdishes, R.id.label, adobe_products));
IntelliJ IDEA 此时会抛出错误:Cannot resolve method setListAdapter。我认为它实际上是需要调用的 ViewDishes.setListAdapter,但它引发了另一个错误:Non static method cannot be referenced from a static content
请告诉我如何克服这个错误?
【问题讨论】:
-
所以你想在listview上显示json数据?
-
你能发布你的java文件吗?
-
@Apoorv 描述中提到了 java 文件。 [pastebin.com/8UEgcyfa]
-
@ZubairAhmadKhan 我想显示解析后的菜单项,而不是确切的 json,如果这就是你的要求的话。
标签: java android listview intellij-idea