Search code examples
javaandroid-layoutpicasso

Image not being loaded in Android


I am new to android. I cannot load picture in my app. The main code is

   package com.example.deepakchethan.imagedisplay;

    import android.support.v7.app.AppCompatActivity;

    import android.os.Bundle;
    import android.widget.ImageView;

    import com.squareup.picasso.Picasso;

    public class MainActivity extends AppCompatActivity {

        ImageView imageView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            imageView=(ImageView)findViewById(R.id.ImageContainer);
            Picasso.with(getApplicationContext()).load("https://image.tmdb.org/t/p/w342/z4x0Bp48ar3Mda8KiPD1vwSY3D8.jpg").into(imageView);
        }
    }`

The xml is

`<?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.deepakchethan.imagedisplay.MainActivity">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/ImageContainer"
            tools:src="@mipmap/ic_launcher"/>

    </RelativeLayout>`

But still the image has not been loaded. What to do now. Please tell. I need to learn.


Solution

  • There is nothing wrong in your code. But have you asked for permission in the manifest file. It is important if you have not added. Type this code to your minifest.

     <uses-permission android:name="android.permission.INTERNET" />
    

    Let me know, if you still have the problem.