小编Mur*_*KSU的帖子

Android Hilt - 多模块项目转换错误

我正在尝试将 hilt 用于包含动态功能的项目。我正面临一个我无法完全理解原因的错误。我收到这样的错误:

java.lang.ClassCastException: com.social.analysis.DaggerApp_HiltComponents_ApplicationC$ActivityRetainedCImpl$ActivityCImpl$FragmentCImpl cannot be cast to com.social.login.intro.IntroFragment_GeneratedInjector
    at com.social.login.intro.Hilt_IntroFragment.inject(Hilt_IntroFragment.java:94)
    at com.social.login.intro.Hilt_IntroFragment.initializeComponentContext(Hilt_IntroFragment.java:58)
    at com.social.login.intro.Hilt_IntroFragment.onAttach(Hilt_IntroFragment.java:50)
    at androidx.fragment.app.Fragment.onAttach(Fragment.java:1602)
    at com.social.login.intro.Hilt_IntroFragment.onAttach(Hilt_IntroFragment.java:40)
Run Code Online (Sandbox Code Playgroud)

LOG?N MODULE 中的我的 ViewModel(动态功能)

class IntroViewModel @Inject constructor(): ViewModel() {
// TODO: Implement the ViewModel
}
Run Code Online (Sandbox Code Playgroud)

登录模块中的我的片段

@AndroidEntryPoint
class IntroFragment : BaseFragment<FragmentIntroBinding, IntroViewModel>(
R.layout.fragment_intro
) {

companion object {
    fun newInstance() = IntroFragment()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
}

override fun onInitDataBinding() {
    viewBinding.viewModel = viewModel
}
}
Run Code Online (Sandbox Code Playgroud)

我在 UI 模块中的基础片段

abstract  class BaseFragment <B: …
Run Code Online (Sandbox Code Playgroud)

android kotlin dagger android-studio dagger-hilt

7
推荐指数
1
解决办法
1571
查看次数

我无法在主机上启动 node.js

我正在尝试在托管中安装我的 node.js 服务器。在 Windows 上运行但在托管中无法运行的服务器。

运行 NPM 安装错误

An error occured during installation of modules. The operation was performed, but check availability of application has failed. Web application responds, but its return code "500 Internal Server Error" or content type before operation "text/html; charset=UTF-8" doesn't equal to contet type after operation "text/html; charset=UTF-8". 
Run Code Online (Sandbox Code Playgroud)

启动服务器错误

Error: error:02016002:system library:stat:No such file or directory
        at Sign.sign (internal/crypto/sig.js:86:29)
        at Object.sign (/home/maksoboi/nodevenv/score/12/lib/node_modules/jsonwebtoken/node_modules/jwa/index.js:152:45)
        at Object.jwsSign [as sign] (/home/maksoboi/nodevenv/score/12/lib/node_modules/jsonwebtoken/node_modules/jws/lib/sign-stream.js:32:24)
        at Object.module.exports [as sign] (/home/maksoboi/nodevenv/score/12/lib/node_modules/jsonwebtoken/sign.js:186:16)
        at ServiceAccountCredential.createAuthJwt_ (/home/maksoboi/nodevenv/score/12/lib/node_modules/firebase-admin/lib/auth/credential.js:101:20) …
Run Code Online (Sandbox Code Playgroud)

javascript linux hosting node.js firebase-admin

3
推荐指数
1
解决办法
2077
查看次数

Dagger Hilt - 如何将 ViewModel 注入适配器?

我正在尝试将 ViewModel 注入适配器中。注入 Fragment 时效果很好。

\n

视图模型:

\n
class HomeViewModel @ViewModelInject constructor(\n): ViewModel() \n
Run Code Online (Sandbox Code Playgroud)\n

分段:

\n
@AndroidEntryPoint\nclass HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(\nR.layout.fragment_home\n) {\n\nprivate val viewModel: HomeViewModel by viewModels()\n
Run Code Online (Sandbox Code Playgroud)\n

目前为止没有问题。但是当我尝试注入适配器时出现问题。

\n
class HomeListAdapter @Inject constructor(\n): BaseListAdapter<Users>(\nitemsSame = { old, new -> old.username == new.username },\ncontentsSame = { old, new -> old == new }\n) {\n\n\n\nprivate val viewModel: HomeViewModel by viewModels() //viewModels() unresolved reference\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n

更新:

\n

如果我尝试使用构造函数注入或字段注入,我会收到以下错误:

\n
  error: [Dagger/MissingBinding] ***.home.HomeViewModel cannot be       provided without an @Inject constructor or …
Run Code Online (Sandbox Code Playgroud)

android viewmodel kotlin dagger dagger-hilt

0
推荐指数
1
解决办法
3086
查看次数