Asset Bekbossynov Asset Bekbossynov - 1 year ago 106
Android Question

Why Picasso library is not working in my project

I am try to do Picasso Gallery using Picasso in Android. Here is my code, which is not working

Picasso.with(MainActivity.this).load(all_images[0]).into(image);


Manifest code

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


Gradle.app file

compile 'com.squareup.picasso:picasso:2.5.2'


Can someone tell me why I cant see images

Answer Source

<uses-permission android:name="android.permission.INTERNET" /> should be define outside of <application> tag

Check below code

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

To detect error you can add callback while using Picasso, You can find below reference example

 Picasso.with(mContext).load(fileImage)
                .placeholder(R.drawable.draw_detailed_view_display)
                .error(R.drawable.draw_detailed_view_display)
                .resize(200, 200)
                .into(holder.mImageEvidence, new Callback() {
                    @Override
                    public void onSuccess() {
                        holder.mMediaEvidencePb.setVisibility(View.GONE);
                    }

                    @Override
                    public void onError() {
                        holder.mErrorImage.setVisibility(View.VISIBLE);
                    }
                });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download