Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:03:57+00:00 2026-06-11T00:03:57+00:00

public class FetchImageAppsActivity extends Activity { /** Called when the activity is first created.

  • 0
public class FetchImageAppsActivity extends Activity {
/** Called when the activity is first created. */
 public static String urlPath = "http://farm1.static.flickr.com/150/399390737_7a3d508730_b.jpg";
 public ImageView imageView;
 boolean usingProxy=true;
 public  String proxyIP="A.B.C.D";
 public  int proxyPort=80;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); 

    imageView =(ImageView) findViewById(R.id.imageViewFetch);

    if(usingProxy==true){
     setProxy();
    }
    try {
        fetch(urlPath);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Drawable image = ImageOperations(this,urlPath,"overflow.png");
    imageView.setImageDrawable(image);


   /* imageView.setMinimumWidth();
    imageView.setMinimumHeight(height);

    imageView.setMaxWidth(width);
    imageView.setMaxHeight(height);
  */
}

private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
    try {
        InputStream is = (InputStream) ((FetchImageAppsActivity) ctx).fetch(url); //error line
        Drawable d = Drawable.createFromStream(is, "src");
        return d;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

public Object fetch(String address) throws MalformedURLException,IOException {
try{
    URL url = new URL(address);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
    url = uri.toURL();
    Log.i("Url:", url+"");
    Object content = url.getContent();
    return content;
    }catch(Exception e){
        e.printStackTrace();
    }
   return null;
   }

public void setProxy()
{ Uri uri = Uri.parse("http://farm1.static.flickr.com/150/399390737_7a3d508730_b.jpg");
  Properties systemProperties = System.getProperties();

  systemProperties.put( "proxySet", "true" );
  systemProperties.setProperty("http.proxyHost",proxyIP);
  systemProperties.setProperty("http.proxyPort","80");
  systemProperties.setProperty("http.nonProxyHosts",uri.getHost()); //uri.getHost()

HttpHost PROXY_HOST=null;
if( usingProxy == true)
     PROXY_HOST = new HttpHost(proxyIP, proxyPort); 
HttpClient client = null;
File f = null;
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2);
HttpParams params = new BasicHttpParams();

params.setParameter(ExecutionContext.HTTP_TARGET_HOST, PROXY_HOST);

params.setBooleanParameter("http.protocol.expect-continue", false);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1));
ConnManagerParams.setMaxTotalConnections(params, 1);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(params, false);
HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET);

HttpConnectionParams.setConnectionTimeout(params,50000);
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry registry = new SchemeRegistry();

registry.register(new Scheme("https", PlainSocketFactory.getSocketFactory(),443));
//if (data != null && data.equals("data")) {
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(),proxyPort));    //uri.getPort()
   //   } else {
    registry.register(new Scheme("https", PlainSocketFactory.getSocketFactory(), proxyPort));
     // }
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, registry);
client = new DefaultHttpClient(cm, params);
//Proxy.NO_PROXY
if(usingProxy == true)
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, PROXY_HOST);
HttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ExecutionContext.HTTP_TARGET_HOST, PROXY_HOST);
try {
    HttpPost request = new HttpPost(); 
    request.setParams(params);


    request.setURI(new URI(uri.toString()));
    request.setHeader("Content-Type","application/x-www-form-urlencoded");
}catch(Exception e){
    System.out.println(e.getMessage());
}
    }
    }

I got the exception while running in android emulator and my machine is connected to proxy enabled WiFi router as folllows

java.net.UnknownHostException: Host is unresolved: farm1.static.flickr.com:80

Error Log:

09-05 13:44:48.817: WARN/System.err(489): java.net.UnknownHostException: Host is unresolved: farm1.static.flickr.com:80
09-05 13:44:48.839: WARN/System.err(489):     at java.net.Socket.connect(Socket.java:1038)
09-05 13:44:48.847: WARN/System.err(489):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
09-05 13:44:48.884: WARN/System.err(489):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
09-05 13:44:48.886: WARN/System.err(489):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
09-05 13:44:48.897: WARN/System.err(489):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
09-05 13:44:48.937: WARN/System.err(489):     at java.net.URLConnection.getContent(URLConnection.java:157)
09-05 13:44:48.937: WARN/System.err(489):     at java.net.URL.getContent(URL.java:621)
09-05 13:44:48.967: WARN/System.err(489):     at com.android.fetchimage.FetchImageAppsActivity.fetch(FetchImageAppsActivity.java:96)
09-05 13:44:48.967: WARN/System.err(489):     at com.android.fetchimage.FetchImageAppsActivity.onCreate(FetchImageAppsActivity.java:62)
09-05 13:44:48.987: WARN/System.err(489):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-05 13:44:48.987: WARN/System.err(489):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-05 13:44:48.987: WARN/System.err(489):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-05 13:44:48.987: WARN/System.err(489):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-05 13:44:48.987: WARN/System.err(489):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-05 13:44:48.987: WARN/System.err(489):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 13:44:48.987: WARN/System.err(489):     at android.os.Looper.loop(Looper.java:123)
09-05 13:44:48.987: WARN/System.err(489):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-05 13:44:49.028: WARN/System.err(489):     at java.lang.reflect.Method.invokeNative(Native Method)
09-05 13:44:49.028: WARN/System.err(489):     at java.lang.reflect.Method.invoke(Method.java:521)
09-05 13:44:49.028: WARN/System.err(489):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-05 13:44:49.047: WARN/System.err(489):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-05 13:44:49.067: WARN/System.err(489):     at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:03:58+00:00Added an answer on June 11, 2026 at 12:03 am

    Set the android Permission for Internet in Manifest.xml file

    android.permission.INTERNET

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class check extends Activity { /** Called when the activity is first created.
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private
public class SaveData extends Activity implements OnClickListener { private DataManipulator dh; static final int
public class MCQSample extends Activity implements OnClickListener{ TextView title; String gotBread; RadioGroup AnswerRG; int
public class HelloWorld { public static void main (String args[]){ System.out.println (Hello ); http://www.google.com
public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.