我在设置片段页面适配器的安全参数时遇到麻烦。我无法设置该值,当它创建片段时会出现以下错误:
kotlin.KotlinNullPointerException at com.eae.mealbook.sleepquality.tabs.TabIngredienteFragment.onCreateView
我想问题出在设置包值的方式上,但是我在网络上找不到任何线索。这是我的适配器代码:
class PaginasSleepQualityAdapter(fm: FragmentManager, aux: Long) : FragmentPagerAdapter(fm)
{
val ppp = aux
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> {
val args = TabIngredienteFragmentArgs.Builder(ppp).build().toBundle()
TabIngredienteFragment().arguments = args
return TabIngredienteFragment()
}
//1 -> TabPasoFragment()//("Pescaderia")
else -> {
val args = TabPasoFragmentArgs.Builder(ppp).build().toBundle()
TabIngredienteFragment().arguments = args
return TabPasoFragment()//("Otros")
}
}
}
和其中一个片段代码
class TabIngredienteFragment() : Fragment() {
/**
* Called when the Fragment is ready to display content to the screen.
*
* This function uses DataBindingUtil to inflate R.layout.fragment_sleep_quality.
*/
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Get a reference to the binding object and inflate the fragment views.
val binding: FragmentTabInputIngredienteBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_tab_input_ingrediente, container, false)
val application = requireNotNull(this.activity).application
val arguments = TabIngredienteFragmentArgs.fromBundle(arguments!!)