1. Download our Official Android App: Forums for Android!

ImageView doesn't display image from url

Discussion in 'Android Development' started by RaoulH, Aug 14, 2017.

  1. RaoulH

    RaoulH Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    9
    Joined:
    Nov 9, 2016

    Nov 9, 2016
    9
    2
    6
    Male
    Hello,

    in my app, i display in "ImageView" widget an image get by url.
    When i launch my app in debug mode in my tablet (android 4.0.3), it is ok, i have the image displayed correctly.
    But when i launch it in my phones (android 6 and android 5), the image isn't display and in the logcat i don't have errors neither warnings.
    Here it's the source code of the activity (source java) and xml
    Code (Java):
    1.  
    2. public class display_ofr extends AppCompatActivity implements IMessage {
    3.  
    4.     private TextView TextLibelle;
    5.     private TextView TextDescription;
    6.     private ImageView imgView;
    7.  
    8.     private JSONArray fURLImagesbyOfer = null;
    9.  
    10.     private static final String GET_IMAGES_BY_OFER = "http://xxxxx";
    11.  
    12.     @Override
    13.     protected void onCreate(Bundle savedInstanceState) {
    14.         super.onCreate(savedInstanceState);
    15.         setContentView(R.layout.activity_display_offer);
    16.  
    17.         TextLibelle = (TextView)findViewById(R.id.textView4);
    18.         TextDescription = (TextView)findViewById(R.id.textView5);
    19.         imgView = (ImageView)findViewById(R.id.imageView);
    20.  
    21.         Intent thisIntent = this.getIntent();
    22.         Bundle b = thisIntent.getExtras();
    23.         if(b!=null){
    24.             String j =(String) b.get(Constants.TAG_LIBELLE);
    25.             TextLibelle.setText(j);
    26.  
    27.             TextDescription.setText(j+"\n"+(String)b.get(Constants.TAG_DESCRPTION));
    28.            
    29.             String offerID = (String)b.get(Constants.TAG_IDOFR);
    30.            
    31.            /**here i used an asynchron task  to get the url in a database*/
    32.             SignupActivity r = new SignupActivity(this,null,GET_IMAGES_BY_OFFER, null);
    33.             r.fOff = this;
    34.             r.execute("" + offerID);
    35.             }
    36.  
    37.     }
    38.  
    39.     @Override
    40.     public void getOffersResultPostExecute(JSONArray pURLImagesbyOffer) {
    41.         fURLImagesbyOffer = pURLImagesbyOffer;
    42.         try {
    43.             String[] urls = new String[fURLImagesbyOffer.length()];
    44.             // looping through All Offers
    45.             for (int i = 0; i < fURLImagesbyOffer.length(); i++) {
    46.                 JSONObject c = null;
    47.  
    48.                 c = fURLImagesbyOffer.getJSONObject(i);
    49.                 urls[i] = c.getString(Constants.TAG_URL_IMAGE);
    50.  
    51.                 /**I use Glide to display the image in the ImageView**/
    52.                 Glide.with(this).load(urls[0]).placeholder(R.drawable.splash_img).into(imgView);
    53.  
    54.             }
    55.            
    56.         } catch (JSONException e) {
    57.             e.printStackTrace();
    58.         }
    59.     }
    60. }
    here it is the xml code:
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     xmlns:tools="http://schemas.android.com/tools"
    4.     android:layout_width="match_parent"
    5.     android:layout_height="match_parent"
    6.     android:paddingBottom="@dimen/activity_vertical_margin"
    7.     android:paddingLeft="@dimen/activity_horizontal_margin"
    8.     android:paddingRight="@dimen/activity_horizontal_margin"
    9.     android:paddingTop="@dimen/activity_vertical_margin"
    10.     tools:context="com.xxxxxx.yyyy_ofer">
    11.  
    12.  
    13.     <TextView
    14.         android:layout_width="wrap_content"
    15.         android:layout_height="wrap_content"
    16.         android:textAppearance="?android:attr/textAppearanceLarge"
    17.         android:text="Large Text"
    18.         android:id="@+id/textView4"
    19.         android:layout_marginTop="34dp"
    20.         android:layout_alignParentTop="true"
    21.         android:layout_alignParentLeft="true"
    22.         android:layout_alignParentStart="true"
    23.         android:layout_marginStart="20dp"
    24.         android:layout_toStartOf="@+id/textView5"
    25.         android:layout_toLeftOf="@+id/textView5" />
    26.  
    27.     <TextView
    28.         android:layout_width="wrap_content"
    29.         android:layout_height="wrap_content"
    30.         android:textAppearance="?android:attr/textAppearanceMedium"
    31.         android:text="Medium Text"
    32.         android:id="@+id/textView5"
    33.  
    34.         android:layout_alignParentRight="true"
    35.         android:layout_marginLeft="20dp"
    36.         android:layout_alignParentEnd="false"
    37.         android:layout_alignParentStart="false" />
    38.  
    39.     <ImageView
    40.         android:layout_width="match_parent"
    41.         android:layout_height="match_parent"
    42.         android:id="@+id/imageView"
    43.  
    44.         android:layout_toEndOf="@+id/textView5"
    45.         android:layout_below="@+id/textView4"
    46.         android:adjustViewBounds="true" />
    47.  
    48. </RelativeLayout>
    49.  
    Please could you help me?

    Thanks for advance,
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,448
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,448
    10,734
    1,988
    Male
    Software developer
    South West of England
    Have you physically connected the phones to your computer, and deployed your app from Android Studio?
    If so, and the application crashed, there will be a stack trace in the Logcat view. We need to see that.
     
  3. RaoulH

    RaoulH Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    9
    Joined:
    Nov 9, 2016

    Nov 9, 2016
    9
    2
    6
    Male
    Hello LV426,
    i connected the phones to my computer and deployed my app from Android Studio, i don't have a crash of my app and in the logcat view i don't have errors and warnings, it is very strange!!
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,448
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,448
    10,734
    1,988
    Male
    Software developer
    South West of England
    That's weird. Do you have a screenshot of how it looks?
     
  5. RaoulH

    RaoulH Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    9
    Joined:
    Nov 9, 2016

    Nov 9, 2016
    9
    2
    6
    Male
    Hello LV426
    Do you want a screenshot of logcat or app?
     
    danacochran54 likes this.

Share This Page

Loading...