gpt4 book ai didi

android - 使用 safeargs 我得到 "required Bundle found Bundle?"

转载 作者:太空狗 更新时间:2023-10-29 13:02:20 24 4
gpt4 key购买 nike

我正在使用 safeargs 传递参数。在 reciving fragment 中,我收到一个编译错误:'Required Bundle Found Bundle?'。看不到错误发生的地方。

Google 搜索,检查文本和无畏教程

出现错误的地方(在'arguments'处)

package com.example.android.naveditoryoutube

import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_two_fragment.*

class FragmentTwo : Fragment() {

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

private lateinit var viewModel: FragmentTwoViewModel

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_two_fragment, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(FragmentTwoViewModel::class.java)

}

override fun onStart() {
super.onStart()
var args = FragmentTwoArgs.fromBundle(arguments)
argText.text = args.calculated_Number
}

}

发送代码:

package com.example.android.naveditoryoutube

import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.Navigation
import kotlinx.android.synthetic.main.fragment_one_fragment.*


class FragmentOne : Fragment() {


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

private lateinit var viewModel: FragmentOneViewModel


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {



return inflater.inflate(R.layout.fragment_one_fragment, container, false)

}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(FragmentOneViewModel::class.java)

var calculated_Number : String = viewModel.sendNewNumber().toString()

button_calculate.setOnClickListener{view: View ->
if (number_box.text.isNotEmpty()){
var number_entered: String = number_box.text.toString()
viewModel.findNewNumber((number_entered))
calculated_Number = viewModel.sendNewNumber()
Navigation.findNavController(view).navigate(FragmentOneDirections.actionFragmentOneToFragmentTwo(calculated_Number))
}


}
}

}

这里出现错误 var args = FragmentTwoArgs.fromBundle(参数)

arguments 应该是 Bundle 但它是 Bundle 吗?

最佳答案

我必须更改它才能使用!!

var args = FragmentTwoArgs.fromBundle(参数!!)

关于android - 使用 safeargs 我得到 "required Bundle found Bundle?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54463535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com