我的 RecyclerView 没有显示,它说没有适配器,但它有

发布于 2025-01-13 20:27:28 字数 745 浏览 0 评论 0原文

在搜索某本书时,我尝试将一些 JSON 获取到 RecyclerView 中,对我来说一切看起来都很好,但是在搜索 RecyclerView 时却没有显示。 我在 Logcat 中收到此错误:E/RecyclerView:未连接适配器;跳过布局 这是唯一返回错误的事情,但我确实设置了 recyclerView.setAdapter(adapter);

我正在使用 Google Books API 使用手机摄像头搜索 ISBN,还可以搜索书名、作者和关键词。我的目标是在 RecyclerView 中显示搜索中的匹配/相似书籍,然后用户可以选择他想要的书籍,单击并打开另一个包含书籍信息的活动。

需要注意的几点:

这是我的 Github 存储库: ISBN 扫描仪

我不知道我现在不知道该怎么办,我对此很生气。 >:(

I tried to fetch some JSON into a RecyclerView when searching for some book, all looks fine to me, but when searching the RecyclerView doens't show up.
I got this error in Logcat: E/RecyclerView: No adapter attached; skipping layout
that's the only thing returning an error, but I did set the recyclerView.setAdapter(adapter);

I'm using Google Books API to search ISBN using the phone camera, and also search book titles, authors and keywords. My aim is to show matching/similar books from search inside the RecyclerView, then the user can choose which one he wants, click and open another activity with the book info there.

Few points to be noted:

Here's my Github repo: ISBN Scanner

I don't know what to do now, I'm getting mad at this. >:(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念三年u 2025-01-20 20:27:28

我检查了您的存储库,发现您没有获取书单,并且在解析 json 数据时出现错误。

这是我得到的异常
对行业标识符没有价值
可能你在这里做错了什么......

JSONArray industryIdentifiers = book_info.getJSONArray("industryIdentifiers");
    if (industryIdentifiers.length() == 1) {
         JSONObject obj = industryIdentifiers.getJSONObject(0);
         ISBN = obj.getString("type") + ": " + obj.getString("identifier");
    } else if (industryIdentifiers.length() == 2) {
         JSONObject obj1 = industryIdentifiers.getJSONObject(0);
         JSONObject obj2 = industryIdentifiers.getJSONObject(1);
         ISBN = obj1.getString("type") + ": " + obj1.getString("identifier") + " - "
         + obj2.getString("type") + ": " + obj2.getString("identifier");
    }
Log.d("ListBook",bookList.toString());
adapter = new MyAdapter(bookList, getApplicationContext());
recyclerView.setAdapter(adapter);

在将其连接到适配器之前打印你的图书清单
另外,在 catch 块中打印异常

catch (JSONException e) {
    Log.d("ListBook",e.getMessage());
    e.printStackTrace();
}

I have checked your repo and i have found that you are not getting booklist and getting error while parsing json data.

here what I got in exception
No value for industryIdentifiers
May be you are doing something wrong here....

JSONArray industryIdentifiers = book_info.getJSONArray("industryIdentifiers");
    if (industryIdentifiers.length() == 1) {
         JSONObject obj = industryIdentifiers.getJSONObject(0);
         ISBN = obj.getString("type") + ": " + obj.getString("identifier");
    } else if (industryIdentifiers.length() == 2) {
         JSONObject obj1 = industryIdentifiers.getJSONObject(0);
         JSONObject obj2 = industryIdentifiers.getJSONObject(1);
         ISBN = obj1.getString("type") + ": " + obj1.getString("identifier") + " - "
         + obj2.getString("type") + ": " + obj2.getString("identifier");
    }
Log.d("ListBook",bookList.toString());
adapter = new MyAdapter(bookList, getApplicationContext());
recyclerView.setAdapter(adapter);

print your book list before attaching it to the adapter
also, print exception in a catch block

catch (JSONException e) {
    Log.d("ListBook",e.getMessage());
    e.printStackTrace();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文