我正在尝试将 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) 我正在尝试在托管中安装我的 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) 我正在尝试将 ViewModel 注入适配器中。注入 Fragment 时效果很好。
\n视图模型:
\nclass HomeViewModel @ViewModelInject constructor(\n): ViewModel() \nRun 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()\nRun Code Online (Sandbox Code Playgroud)\n目前为止没有问题。但是当我尝试注入适配器时出现问题。
\nclass 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\nRun 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 ×2
dagger ×2
dagger-hilt ×2
kotlin ×2
hosting ×1
javascript ×1
linux ×1
node.js ×1
viewmodel ×1