android - Not able to show image from url in imageview -


I am trying to bring an irreversible URL and trying to set it in the image view so that the image is smaller And I'm using asynctask here's the main activity code. I've tried many code from the diff site, but nothing seems to be working plz does not suggest the volume library.

  package com.example.jsonimage; Import java.io.file; Import java.io.IOException; Import java.io.InputStream; Import java.net.HttpURLConnection; Import java.net.MalformedURLException; Import java.net.URL; Import android.os.asyncTask; Importroid.os.Bundle; Import android App Import Android.graphics. Bitmap; Import and roid.graphics.BitmapFactory; Import android.view.Menu; Import android.widget.ImageView; Public classroom enhances main activity activity {Thread T; Bitmap bitmap; Image view iv; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Iv = (imageView) findViewById (R.id.imageView1); // runthread (); } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Enhancing Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fulao (R. menu menu, menu); Back true; } Public Class Loadimize Ascend Task & lt; Zero, zero, zero> {@ Override Protected Woud Do Inbackground (Zero ... Parameter) {// TODO Auto generated method stub url url; Try {url = new URL ("http://wptrafficanalyzer.in//p//demo1//india.png"); InputStream = url.openstream (); Bitmap = bitmapfichtor. Decodestream (is); } Grip (Malformedlexception E) {// TODO self-generated blocking block e.printStackTrace (); } // HttpURLConnection huc = (HttpURLConnection) url.openConnection (); //huc.connect (); Grip (IOException E) {// TODO auto generated grip block e.printStackTrace (); } Return tap; } @Override Secure Zero on postexec (zero result) {// TODO auto generated method stub super.onPostExecute (results); Iv.setImageBitmap (bitmap); }}}}    

You are not calling async functions Try on your main activity :

  New loadimage (). carry about ();   

If you are not working, you can still use this function to get a bitmap from the URL:

  public stable Bitmap getBitmapFromURL (string src) {try {url = new URL (src); HttpURL Connection Connection = (HttpURL Connection) url.openConnection (); connection.setDoInput (true); Connection.connect (); InputStream input = connection.getInputStream (); Bitmap myBitmap = Bitmapfinder Aodestream; My return refund; } Hold (IOException e) {e.printStackTrace (); Return tap; }}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -