Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException #44

Open
athkalia opened this issue Dec 28, 2015 · 4 comments
Open

NullPointerException #44

athkalia opened this issue Dec 28, 2015 · 4 comments

Comments

@athkalia
Copy link

Hello, I am getting a NullPointerException from your library. Unfortunately the code is obfuscated so I can't trace it down 100%

java.lang.NullPointerException: Attempt to invoke virtual method 'double org.json.JSONObject.optDouble(java.lang.String)' on a null object reference
    at com.survivingwithandroid.weather.lib.provider.openweathermap.OpenweathermapProvider.getCurrentCondition(SourceFile:1516)
    at bno.onResponse(SourceFile:380)
    at bkr.execute(SourceFile:162)
    at com.squareup.okhttp.internal.NamedRunnable.run(SourceFile:33)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)

Edit:

We are getting the exception because the response is a weird openweathermap response, error 401 that can't be parsed by your library. The easiest way to fix this is to catch NullpointExceptions and return an empty weather object.

The json we receive is:
{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}

@athkalia
Copy link
Author

Note:

In their json respond api here
http://openweathermap.org/current#current_JSON
there's no "gust" field at all ! Maybe you should just remove that ?

Cheers

@Seichis
Copy link

Seichis commented Apr 24, 2016

@athkalia So this is still an issue. How did you deal with it?

@athkalia
Copy link
Author

I made a fork that catches all exceptions and forwards them accordingly in the already existing onError listeners. It's this one.
https://github.com/athkalia/WeatherLib . This is the only change:
athkalia@44a43e0

@tsakmalis
Copy link

The same problem happens to me! How can I handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants