survivingwithandroid / WeatherLib

Android Weather Library: android weather lib to develop weather based app fast and easily
http://survivingwithandroid.github.io/WeatherLib/
640 stars 170 forks source link

NullPointerException When Giving Config Settings #55

Closed vdaita closed 6 years ago

vdaita commented 6 years ago

I am trying to use WeatherLib in my app. However, when I try to set up the config, I get a NullPointerException. I cannot find a way to fix it, and I have used the code provided. Any pointers?

` WeatherClient weatherClient = WeatherClientDefault.getInstance();

    weatherClient.init(this);
    WeatherConfig config = new WeatherConfig();
    config.unitSystem = WeatherConfig.UNIT_SYSTEM.M;
    config.lang = "en";
    config.maxResult = 5;
    config.numDays = 6;
    weatherClient.updateWeatherConfig(config); //This is where I get the error
    IWeatherProvider provider = null;
    try{
        provider = WeatherProviderFactory.createProvider(new YahooProviderType(), config);
        weatherClient.setProvider(provider);
    } catch (Throwable t){}

    ListView listView = findViewById(R.id.list);

    WeatherAdapter adapter = new WeatherAdapter(getApplicationContext(), R.layout.row_view, cities, weatherClient);
    listView.setAdapter(adapter);`

Any help provided is appreciated.

vdaita commented 6 years ago

Here is the exact error that I got:

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.survivingwithandroid.weather.lib.provider.IWeatherProvider.setConfig(com.survivingwithandroid.weather.lib.WeatherConfig)' on a null object reference

vdaita commented 6 years ago

Updated to 1.6