-2

I don't understand why the app closes:

java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLongitude()' on a null object reference
  private void getWeatherInformation() {
        compositeDisposable.add(mSevice.getWeatherByLatLhg(String.valueOf(Common.current_location),
                String.valueOf(Common.current_location.getLongitude()),
                Common.APP_ID,
                "metric")
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<WeatherResponse>() {
                    @Override
                    public void accept(WeatherResponse weatherResponse) throws Exception {
                        Picasso.get().load(new StringBuilder("https://openweathermap.org/img/wn/")
                                .append(weatherResponse.getWeather().get(0).getIcon()).append(".png").toString()).into(imageWeather);

                        cityName.setText(weatherResponse.getName());
                        description.setText(new StringBuilder("Weather in ")
                        .append(weatherResponse.getName()).toString());
                        temperature.setText(new StringBuilder(String.valueOf(weatherResponse.getMain().getTemp()))
                        .append("°C"));
                        dateTime.setText(Common.convertUnixToDate(weatherResponse.getDt()));

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        Toast.makeText(getActivity(), ""+throwable.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                })

        );
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Common.current_location.getLongitude() is your issue

either Common or Common.current_location is null (not assigned a value), and so you are calling the getLongitude() method upon something that does not exist.

omoshiroiii
  • 643
  • 5
  • 11