Closed Advice-Dog closed 7 years ago
Thanks for the report. Will look into it next week.
Throwing an exception when there's no internet is intended. You should catch the exception and show an appropriate error message to the user. Could you tell me which exception you get?
I actually wasn't able to get any exception at all, there was no callstack given. Which sounds weird, right.
This is all I was able to see: E/LOG: ║ Getting item for Pokedex. E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.app.poke, PID: 396
Looks like Android is catching your exception from your AsyncTask and reporting the error. You'll need to put a try/catch in the AsyncTask.
Ok, I tried it a few more times.
Without a try catch, I did see an exception once ( Stream was closed ), but I just retried that and it went back to no exception again.
With a try/catch, it was able to catch it, but why am I unable to see that that call will throw an exception? Is it because of Kotlin?
Yes, one of Kotlin's features is the lack of checked exceptions. On Wed, Dec 14, 2016 at 3:18 PM Chris notifications@github.com wrote:
Ok, I tried it a few more times.
Without a try catch, I did see an exception once ( Stream was closed ), but I just retried that and it went back to no exception again.
With a try/catch, it was able to catch it, but why am I unable to see that that call will throw an exception? Is it because of Kotlin?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/PokeAPI/pokekotlin/issues/57#issuecomment-267144565, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQlpcQbUQbF2cdB-1rdbF-NuO1pnTEWks5rIE8ogaJpZM4LGlj1 .
Alright.
Would you mind updating the Java example to show how to get the network call off the main thread, and also to make sure people are aware that it can throw exceptions?
Sure, will do. Created issue #58.
I'm having the same issue with the Java example. I'm well versed in Java, but very new to Android.
I have:
<uses-permission android:name="android.permission.INTERNET" />
to AndroidManifest.xml
.PokeApi pokeApi = new PokeApiClient();
PokemonSpecies bulbasaur = pokeApi.getPokemonSpecies(1);
But the app still crashes and there's no stack trace to help me. Any help? @sargunster @Advice-Dog
Do you have internet? If not, then you need to make sure you try/catch the network call. Also make sure it's on another thread, as you can't do network calls on the main thread.
I guess I should learn a bit more about Android first. Indeed, there was a NetworkOnMainThreadException I didn't pay much attention to. I'm using AsyncTasks now to make the request in a worker thread. Thank you @Advice-Dog! 😄
No problems, good luck. 👍
While using the example, I noticed that the code would crash my application if my device didn't have internet. There was also no callstack present. Should have some way to handle this case, and also something in the logging.