Package does not exist when import kotlin class into java class

Viewed 549

I'm sorry if I'm asking a basic question, but I'm new to android app programming. I have a class written in kotlin along the following path: package com.albs.calendar And a class written in Java along the following path: package com.albs.ui.gallery;

I'm trying to import kotlin into java (import com.albs.calendar.Example5Fragment;), but at the build stage I get the following error:

error: package com.albs.calendar does not exist
import com.albs.calendar.Example5Fragment;

Here is the code of Example5Fragment:

package com.albs.calendar

class Example5Fragment : BaseFragment(R.layout.example_5_fragment), HasToolbar {

    override val toolbar: Toolbar?
        get() = null

    override val titleRes: Int = R.string.example_5_title

    private var selectedDate: LocalDate? = null
    private val monthTitleFormatter = DateTimeFormatter.ofPattern("MMMM")

    private val flightsAdapter = Example5FlightsAdapter()
    private val flights = generateFlights().groupBy { it.time.toLocalDate() }

    private lateinit var binding: Example5FragmentBinding

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding = Example5FragmentBinding.bind(view)
        ...

    }

    override fun onStart() {
        super.onStart()
//        requireActivity().window.statusBarColor = requireContext().getColorCompat(R.color.example_5_toolbar_color)
    }

    override fun onStop() {
        super.onStop()
//        requireActivity().window.statusBarColor = requireContext().getColorCompat(R.color.colorPrimaryDark)
    }

    private fun updateAdapterForDate(date: LocalDate?) {
        flightsAdapter.flights.clear()
        flightsAdapter.flights.addAll(flights[date].orEmpty())
        flightsAdapter.notifyDataSetChanged()
    }
}

UPD enter image description here

UPD2 The problem was solved by creating a new project and moving the code there.

1 Answers

if you are using android studio, just create an object or make a call to that class. like this...example


So, now I want to select the vote contract delegate and then enter.
Android studio would automatically import it.
Just look at the package name at the right section and select the correct one.
This works for both kotlin and java.
You don't ever have to import it manually.
IDEs nowadays are smart enough to suggest that for you.

Related