0

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

2 Answers2

1

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

eriuzo
  • 1,687
  • 1
  • 14
  • 16
0

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.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108