question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please guide : org.kodein.di.Kodein$NotFoundException: No binding found

See original GitHub issue

Hi Team,

I am not sure if this is an issue or I am doing something wrong. Please guide.

Issue :

org.kodein.di.Kodein$NotFoundException: No binding found for bind<WeatherForecastDatabase>() with ?<CurrentWeatherFragment>().? { ? }
    Registered in this Kodein container:
            bind<CurrentWeatherDao>() with singleton { CurrentWeatherDao }
            bind<CurrentWeatherViewModelFactory>() with provider { CurrentWeatherViewModelFactory }
            bind<Unit>() with singleton { Unit }
            bind<WeatherNetworkDataSource>() with singleton { WeatherNetworkDataSourceImpl }
            bind<WeatherForecastRepository>() with singleton { WeatherForecastRepositoryImpl }
            bind<ConnectivityInterceptor>() with singleton { ConnectivityInterceptorImpl }
            bind<WeatherApiService>() with singleton { WeatherApiService }

I am using below grade dependencies,

implementation "org.kodein.di:kodein-di-generic-jvm:6.1.0"
implementation "org.kodein.di:kodein-di-framework-android-x:6.1.0"

Here is my Application class below, which I have also added in AndroidManifest.xml,

class WeatherForecastApplication : Application(), KodeinAware {

    override val kodein = Kodein.lazy {
        import(androidXModule(this@WeatherForecastApplication))

        bind() from singleton { WeatherForecastDatabase(instance()) }

        bind() from singleton { instance<WeatherForecastDatabase>().getCurrentWeatherDao() }

        bind<ConnectivityInterceptor>() with singleton { ConnectivityInterceptorImpl(instance()) }

        bind() from singleton { WeatherApiService(instance()) }

        bind<WeatherNetworkDataSource>() with singleton { WeatherNetworkDataSourceImpl(instance()) }

        bind<WeatherForecastRepository>() with singleton { WeatherForecastRepositoryImpl(instance(), instance()) }

        bind() from provider { CurrentWeatherViewModelFactory(instance()) }
    }

    override fun onCreate() {
        super.onCreate()

        // init threetenbp library.
        AndroidThreeTen.init(this)
    }

}

And this is how I am referencing instances in Fragment,

class CurrentWeatherFragment : Fragment(), KodeinAware {
    override val kodein by kodein()
    private val factory: CurrentWeatherViewModelFactory by instance()

    private lateinit var viewModel: CurrentWeatherViewModel

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

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SUMAR7commented, Feb 12, 2019

I am facing a similar issue: No binding found for bind<Activity>() with ?<MainActivity>().? { ? } Registered in this Kodein container:

Kodein Version : 6.1.0

My Activity Code class MainActivity : AppCompatActivity(), KodeinAware { override val kodein by kodein() private val fusedLocationProviderClient: FusedLocationProviderClient by instance() ............................... .............................. }

0reactions
EhsanFallahicommented, Jan 19, 2020

@SalomonBrys

I did recheck my WeatherForecastDatabase as suggested by you, and found that although it is a class, the function that was used to get an instance of this class returned nothing, which essentially meant Unit. Have made proper change and was able to get the app running.

Thanks a lot for your input. I had no clue that this could be a problem even though I read the crash logs mentioned above so many times. Had given up…

Maybe the team can add this in one of their README, as when this can happen and how to solve it?

Thanks again!

hi…please display your change in function into WeatherForecastDatabase…Because I have such a problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

org.kodein.di.Kodein$NotFoundException: No binding found ...
Hi Team, I am not sure if this is an issue or I am doing something wrong. Please guide. Issue : org.kodein.di.Kodein$NotFoundException: No...
Read more >
Kotlin Kodein NotFoundException: No binding found for bind ...
The fragment inflates and handles all interaction but the networking layer dependency is somehow missing because I receive: NotFoundException: ...
Read more >
No binding found for bind<String>() with ?<Fragment>()-kotlin
You should bind the String "class" with an instance of itself inside the kodein.lazy initialization before you bind classes that use instances of...
Read more >
Thanks for the tutorial. With:. I have the following exception
java.lang.RuntimeException: Unable to start activity ComponentInfo{…}: org.kodein.di.Kodein$NotFoundException: No binding found for bind ...
Read more >
hey Guys I m struggling with a strange issue I m injecting S | Kodein ...
Caused by: org.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>(tag = "settings") with ?<Context>().? { ? }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found