0

I am stuck with this problem and I am not getting any solution to that, I want a tablayout with viewpager2 which has recycler view inside it. MainActivity.kt:-

@RequiresApi(Build.VERSION_CODES.Q)
override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)
    pager = findViewById(R.id.view_pager)
    tab = findViewById(R.id.extra)

    val adapter = SectionsPagerAdapter(supportFragmentManager, lifecycle)
    pager.adapter = adapter
    TabLayoutMediator(tab,pager){tab,position ->
    when(position){
        0->{
            tab.text="RECENT"
        }
        1->{
            tab.text="SAVED"
        }
        2->{
            tab.text="TOOLS"
        }
    }
    }.attach()

SectionPagerAdapter.kt:-

  class SectionsPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle):
    FragmentStateAdapter(fragmentManager, lifecycle) {
override fun getItemCount(): Int {
    return 3    }

      override fun createFragment(position: Int): Fragment {
          // return a particular fragment page

          return when (position) {
              0 -> {
                  return tabrecentFragment()
              }
              1 -> {
                  return tabsavedFragment()
              }
              2 -> {
                  return tabtoolsFragment()
              }

              else -> {
                  return tabrecentFragment()
              }
          }
      }     
    }

I am getting error-: Installation failed due to: ''package install-create -r -t --user current --full --dont-kill -S 7376065' returns error 'Unknown failure: cmd: Can't find service: package'' Retry Failed to launch an application on all devices.

And when I connect my android device to run the app then it gives the error:-

Caused by: java.lang.NullPointerException: findViewById(R.id.extra) must not be null at com.whatsappstatussaverlatest.MainActivitySSW.onCreate(MainActivitySSW.kt:125)

If you have any solution then please help

  • What problem are you encountering doing that? What's wrong with the code in this question? – Ryan M Jan 28 '23 at 04:05
  • @RyanM I am unable to run the application it is giving me the error which I have mentioned in the post above – Vivek Jaiswal Feb 01 '23 at 22:20
  • You don't have a view with ID `extra` in your layout. You need to fix that. Take a look at the last section of my answer here: https://stackoverflow.com/a/62867558/208273 – Ryan M Feb 01 '23 at 23:31

0 Answers0