asdff asdff - 4 months ago 26
Android Question

Picasso error loading image?

I'm trying to use the Picasso library but it is not working. I think my error is with the

Picasso.with(Context)
i might be using wrong parameter. I included the code for the MainActivity and ListClass. The picture is not loaded and does not appear in the app just white space.

UPDATE!! the " which i was missing has nothing to do with the error. just wrong copy. it gives me error on the
this


MainActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;
import android.widget.FrameLayout;
import android.widget.Button;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import com.squareup.picasso.Picasso;







public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

ListView list;
imageHandler imagess = new imageHandler();

String[] web = {"Trial "};
Integer[] imageId = { R.drawable.ic_menu_camera };
//Drawable[] imageId = { imagess.LoadImageFromWebOperations("http://egyptianstreets.com/wp-content/uploads/2016/08/satelliteegypt-400x240.jpg")};

Handler handler;
Button button;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
listClass adapter = new
listClass(MainActivity.this, web, imageId);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
}
});

}


ListClass that i used the Picasso library to load the picture from the URL;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.webkit.WebView;
import com.squareup.picasso.Picasso;

public class listClass extends ArrayAdapter<String>{



//Next three lines introduces Variables to use in the class
private final Activity context;
private final String[] web;
private final Integer[] imageId;

//Constructor to get Web, Image and context to set adapter
public listClass(Activity context, String[] web, Integer [] imageId) {

super(context, R.layout.list, web);
this.context = context;
this.web = web;
this.imageId = imageId;

}

//Public method to ...
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list, null, true);

TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web[position]);
Picasso.with(this).load("http://egyptianstreets.com/wp-content/uploads/2016/08/egyptischemoefti.jpg").resize(60,60).into(imageView").resize(50,50).centerCrop().
into(imageView);
return rowView;
}
}

Answer

Here error is you are using library in wrong way.

" is not valid here.

Also you have used .into(imageView) and resize(..) twice.

Try this.

 Picasso.with(context).load("http://egyptianstreets.com/wp-content/uploads/2016/08/egyptischemoefti.jpg").resize(60,60).centerCrop().
            into(imageView);