GithubHelp home page GithubHelp logo

Comments (2)

rosuH avatar rosuH commented on July 26, 2024

@moonGosun 我大概了解了问题出现在哪了。这个问题不会对正常使用有什么影响。

问题原因

直接原因

RecyclerView 被创建的时候没有设置 Adapter 的时候会抛出这个错误。

分析

FilePickerActivity.kt 文件的 prepareLauncher() 方法中,我用了协程来实现异步文件 I/O 然后更新 UI 的操作。(参看 #7

注意两点:

  1. prepareLauncher() 是在onCreate()中调用的

在该 launch 作用域最后调用了initView()这个方法:

private fun prepareLauncher() {
    // 执行顺序 ①
    launch {
        ...
    // 执行顺序 ③
        initView()
    }
    // 执行顺序 ②
}

所以最后的执行顺序会变成

onCreate() --> prepareLauncher() --> onCreate() 结束 --> initView()

onCreate() 结束后没有为 RecyclerView 设置Adapter,所以提示了错误。


这是协程的黑魔法😄,我会考虑优化一下这个东西。
感谢提出建议~

from androidfilepicker.

moonGosun avatar moonGosun commented on July 26, 2024

good~

from androidfilepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.