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

  • Home
  • SEARCH
  • 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 7962229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:16:55+00:00 2026-06-04T05:16:55+00:00

Here I tried to retrieve image from Url Connection , but i m not

  • 0

Here I tried to retrieve image from Url Connection , but i m not able to get , help to resolve this problem

HttpDownloadActivity.java coding

package com.HttpDownload;

import android.app.Activity;
import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class HttpDownloadActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out.print("HI.....");
        Bitmap bitmap =
                DownloadImage(
                "http://bestpropertyworld.com/photos/blue-fish.jpg");
       ImageView img = (ImageView) findViewById(R.id.img);
                img.setImageBitmap(bitmap);
            /*  String str =
                        DownloadText("http://www.appleinsider.com/appleinsider.rss");
                        txt = (TextView) findViewById(R.id.text);
                        txt.setText(str);*/
    }

private Bitmap DownloadImage(String URL)
{
    System.out.print("Bitmap DownloadImage");
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
    private InputStream OpenHttpConnection(String urlString)
            throws IOException
            {
        System.out.print("InputStream OpenHttpConnection");
            InputStream in = null;
            int response = -1;
            URL url = new URL(urlString);
            URLConnection conn = url.openConnection();
            if (!(conn instanceof HttpURLConnection))
            throw new IOException("Not an HTTP connection");
            try{
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            response = httpConn.getResponseCode();
            if (response == HttpURLConnection.HTTP_OK) {
            in = httpConn.getInputStream();
            }
            }
            catch (Exception ex)
            {
            throw new IOException("Error connecting");
            }
            return in;
            }

}

main.xml coding

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/text"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

Mainfest coding:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.HttpDownload"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HttpDownloadActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

output in logcat

05-21 11:13:53.296: D/AndroidRuntime(620): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-21 11:13:53.296: D/AndroidRuntime(620): CheckJNI is ON
05-21 11:13:54.166: D/AndroidRuntime(620): Calling main entry com.android.commands.pm.Pm
05-21 11:13:54.216: D/AndroidRuntime(620): Shutting down VM
05-21 11:13:54.226: D/dalvikvm(620): GC_CONCURRENT freed 101K, 78% free 463K/2048K, paused 1ms+1ms
05-21 11:13:54.236: D/dalvikvm(620): Debugger has detached; object registry had 1 entries
05-21 11:13:54.270: I/AndroidRuntime(620): NOTE: attach of thread 'Binder Thread #3' failed
05-21 11:13:54.836: D/AndroidRuntime(633): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
05-21 11:13:54.836: D/AndroidRuntime(633): CheckJNI is ON
05-21 11:13:55.646: D/AndroidRuntime(633): Calling main entry com.android.commands.am.Am
05-21 11:13:55.686: I/ActivityManager(87): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.HttpDownload/.HttpDownloadActivity} from pid 633
05-21 11:13:55.686: W/WindowManager(87): Failure taking screenshot for (180x300) to layer 21005
05-21 11:13:55.736: W/NetworkManagementSocketTagger(87): setKernelCountSet(10043, 1) failed with errno -2
05-21 11:13:55.746: D/AndroidRuntime(633): Shutting down VM
05-21 11:13:55.766: D/dalvikvm(633): GC_CONCURRENT freed 102K, 77% free 485K/2048K, paused 1ms+2ms
05-21 11:13:55.777: D/dalvikvm(633): Debugger has detached; object registry had 1 entries
05-21 11:13:55.816: I/AndroidRuntime(633): NOTE: attach of thread 'Binder Thread #3' failed
05-21 11:13:56.186: W/System.err(565): java.io.IOException: Error connecting
05-21 11:13:56.186: W/System.err(565):  at com.HttpDownload.HttpDownloadActivity.OpenHttpConnection(HttpDownloadActivity.java:83)
05-21 11:13:56.226: W/System.err(565):  at com.HttpDownload.HttpDownloadActivity.DownloadImage(HttpDownloadActivity.java:51)
05-21 11:13:56.246: I/Process(87): Sending signal. PID: 565 SIG: 3
05-21 11:13:56.246: I/dalvikvm(565): threadid=3: reacting to signal 3
05-21 11:13:56.296: W/System.err(565):  at com.HttpDownload.HttpDownloadActivity.onCreate(HttpDownloadActivity.java:35)
05-21 11:13:56.296: W/System.err(565):  at android.app.Activity.performCreate(Activity.java:4465)
05-21 11:13:56.307: W/System.err(565):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-21 11:13:56.307: W/System.err(565):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-21 11:13:56.307: W/System.err(565):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-21 11:13:56.307: W/System.err(565):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-21 11:13:56.316: W/System.err(565):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-21 11:13:56.316: I/dalvikvm(87): Jit: resizing JitTable from 4096 to 8192
05-21 11:13:56.326: W/System.err(565):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 11:13:56.326: W/System.err(565):  at android.os.Looper.loop(Looper.java:137)
05-21 11:13:56.326: I/dalvikvm(565): Wrote stack traces to '/data/anr/traces.txt'
05-21 11:13:56.346: W/System.err(565):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-21 11:13:56.346: W/System.err(565):  at java.lang.reflect.Method.invokeNative(Native Method)
05-21 11:13:56.346: W/System.err(565):  at java.lang.reflect.Method.invoke(Method.java:511)
05-21 11:13:56.356: W/System.err(565):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-21 11:13:56.366: W/System.err(565):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-21 11:13:56.366: W/System.err(565):  at dalvik.system.NativeStart.main(Native Method)
05-21 11:13:56.596: D/dalvikvm(87): GC_CONCURRENT freed 330K, 14% free 11313K/13127K, paused 6ms+10ms
05-21 11:13:56.796: I/Process(87): Sending signal. PID: 565 SIG: 3
05-21 11:13:56.796: I/dalvikvm(565): threadid=3: reacting to signal 3
05-21 11:13:56.806: I/dalvikvm(565): Wrote stack traces to '/data/anr/traces.txt'
05-21 11:13:56.896: I/ActivityManager(87): Displayed com.HttpDownload/.HttpDownloadActivity: +1s169ms
05-21 11:13:57.196: W/InputManagerService(87): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@415b29b0 (uid=10013 pid=184)
05-21 11:13:57.246: W/NetworkManagementSocketTagger(87): setKernelCountSet(10013, 0) failed with errno -2

It seems i am getting in catch, i dont know exactly, help me in this process Thankyou in advance

  • 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-04T05:16:56+00:00Added an answer on June 4, 2026 at 5:16 am

    Downloading image from a url can be simply done by using

     URL url = new URL(address);
     Object content = url.getContent();
    

    Simply check Displaying an Image from the web

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

Sidebar

Related Questions

I tried searching here , but it couldn't help me much .. I want
I tried to compile Ercia Sadun's sample code here , but this error came
I tried this JavaScript but it doesn't work - here I need to change
I tried following some of the code from here and here , but I
So, what I'm actually looking for is this solution: Get/pick an image from Android's
I've tried the solution here , but it doesn't work. My table is like
I tried to use TestNG with Apache Ivy , but was unsuccessful. Here is
Well I tried to figure out is this possible in any way. Here is
I'm trying to retrieve images from wikimedia using the existing api, but there seems
I am currently stuck with this problem of displaying an image using HtmlHelper class.

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.