crash load image from website
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog">Download a file with Android, and showing the progress in a ProgressDialog</a>  </p>
</blockquote>



<p>I am trying to load a image from a website,I saw this question : <a href="http://stackoverflow.com/questions/8992964/android-load-from-url-to-bitmap">Android load from URL to Bitmap</a> but my application crash at this line :
conn.connect();</p>

<pre><code>public class HTTPTest extends Activity {

ImageView imView;
String imageUrl = "http://api.androidhive.info/images/sample.jpg";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    Button bt3 = (Button) findViewById(R.id.get_imagebt);
    bt3.setOnClickListener(getImgListener);
    imView = (ImageView) findViewById(R.id.imview);
}

View.OnClickListener getImgListener = new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        downloadFile(imageUrl);
    }
};

Bitmap bmImg;

void downloadFile(String fileUrl) {
    URL myFileUrl = null;
    try {
        myFileUrl = new URL(fileUrl);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) myFileUrl
                .openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();

        bmImg = BitmapFactory.decodeStream(is);
        imView.setImageBitmap(bmImg);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
</code></pre>

<p>main.xml :</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&gt;
&lt;TextView  
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, HTTPImage load test"
/&gt;
    &lt;Button 
android:id="@+id/get_imagebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get an image"
android:layout_gravity="center"
/&gt;  
&lt;ImageView 
android:id="@+id/imview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/&gt;
</code></pre>

<p></p>

<p>My manifest :</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidtest"
android:versionCode="1"
android:versionName="1.0" &gt;
&lt;uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" /&gt;


&lt;application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" &gt;
    &lt;activity
        android:name="com.example.androidtest.HTTPTest"
        android:label="@string/app_name" &gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;

            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
&lt;/application&gt;

&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
&lt;!-- Permission to write to external storage --&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
&lt;/manifest&gt;
</code></pre>

<p>Thanks in advance for you help!</p>

<p>Germain.</p>
