Yussuf Sassi
Yussuf Sassi

Reputation: 25

Picasso won't show image from imgur

This is the code i use, the library is imported from the jar, the image link works fine and i even added the internet permissions in the AndroidManifest.xml. The problem is that when i start the app it opens and closes without showing anything.

package my.pkg.name;

import com.squareup.picasso.*;
import android.R.id.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.id.immagine);
        ImageView targetImageView = (ImageView) findViewById(R.id.immagine);
        String internetUrl = "http://i.imgur.com/DvpvklR.png";

        Picasso
            .with(this)
            .load(internetUrl)
            .into(targetImageView);
       }  
}

And this is the layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="just a string"
    />
<ImageView 
          android:id="@+id/immagine"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:contentDescription="213"
/>
</LinearLayout>

Thank you

Upvotes: 0

Views: 217

Answers (2)

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

Also, remember, except that Layout as @eriuzo said, that could be due to Activity :

public class MainActivity extends Activity

For these situations, you should check the logcats if something is wrong.but, You can use that with AppCompatActivity that should solve the problem.

Upvotes: 0

eriuzo
eriuzo

Reputation: 1687

setContentView(R.id.immagine); is wrong. Usually you put R.layout.something into setContentView.

Upvotes: 1

Related Questions