The moose likes Android and the fly likes Android httpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Android httpURLConnection" Watch "Android httpURLConnection" New topic

Android httpURLConnection

Martial Britto

Joined: Aug 18, 2011
Posts: 1

The Code below on execution in android throws IOException but not when executed as a java project.

This piece of code works fine when executed as a java project but not as an android project.. kindly reply soon
zoheb hassan
Ranch Hand

Joined: Apr 01, 2009
Posts: 146

Can you post the manifest, Have you added this node <uses-permission android:name="android.permission.INTERNET" /> in your manifest
lillinonahfirstname lillinonahlastname

Joined: Nov 12, 2011
Posts: 1
as @zoheb has corrected pointed out, missing <uses-permission android:name="android.permission.INTERNET" /> sounds like the culprit and is common

that said for others coming across this issue who have already added the INTERNET permission, another thing to check is to see if you are getting the NetworkOnMainThreadException

in @Martial's code snippet only MalforedURLException and IOException are being caught therefore would miss the NetworkOnMainThreadException if this snippet happened to be on the main thread (not suggesting it is in @Martial's case)

the idea is to safeguard the responsiveness of the main thread by disallowing network, for more info see here:

Peter Johnson

Joined: May 14, 2008
Posts: 5811

"lillinonahfirstname lillinonahlastname", please see your private messages regarding an important administrative matter.

JBoss In Action
I agree. Here's the link: http://aspose.com/file-tools
subject: Android httpURLConnection
Similar Threads
please help me in how to create a java application to give url and get the requested page
invoking a servlet from client Java code
URL connection connectiontimeout and readtimeout issues
how to create a HTTP Client Program for servlet
Multithreading client socket throws Stream corrupted exception