John Rumpel
John Rumpel

Reputation: 4615

java.net.UnknownHostException @ Android (Simple HttpResponse-Code)

Dear Ladys and Gentleman,

I did my homework, I've googled a lot and I think I know where the Problem can be located:

I want to fetch some simple JSON formated data from local Apache. When I start a

httpclient.execute(httppost)

... I receive (via printStackTrace()):

02-04 13:26:12.292: W/System.err(9606): java.net.UnknownHostException: http://localhost/JSON/request2.php
02-04 13:26:12.292: W/System.err(9606): java.net.UnknownHostException: http://127.0.0.1/JSON/request2.php
(after including the line "127.0.0.1 www.localhost.alt" to my Host file):
02-04 13:26:12.292: W/System.err(9606): java.net.UnknownHostException: http://www.localhost.alt/JSON/request2.php

I really need help. Have you any Ideas?

Greeting,

John


edit:

I made some research and found this article: Emulator Networking

As you can see localhost & 127.0.0.1 are reserved for the emulators loopbacks itself!

Thats why Dark is absolutely right when he said I have to use 10.0.2.2 there. Thanks a lot!

Upvotes: 1

Views: 1795

Answers (1)

Suave Nti
Suave Nti

Reputation: 3739

It would have been nice if you posted your code along with the stacktrace.

But, Try using

  10.0.2.2 instead of localhost or 127.0.0.1

also add this

    <uses-permission android:name="android.permission.INTERNET"/>

to your AndroidManifest.xml

Upvotes: 6

Related Questions