I’m working on a couple of projects that interact with REST api’s and consume JSON data and in doing so I use the DefaultHttpClient from apache, located in the Android framework.
The Error
Last night I was working on a project and kept getting this error:
java.lang.IllegalStateException: Target host must not be null, or set in parameters.
I spent about 20 minutes banging my head against the wall, inspecting through the debugger, googling, etc. Long story short, there was not much info out there on how to fix this error. I found out what it was after another 20 minutes banging my head against the keyboard.
The Issue
I was connecting to website with the following URI:
www.example.org/api/json/get_stuff
The problem is that I was missing the “http://”. Therefore it should have been:
http://www.example.org/api/json/get_stuff
This fixed the issue. The reason is that the scheme was not provided in the URI. As soon as this was changed the entire client worked as expected.
Normally I wouldn’t blog this, but this is one of those issues where if I can’t find the resolution to the issue, I might as well blog it so others can find it when they run into it.