如何在android中将picasso的ImageView设置为简单适配器列表?

如何在android中将picasso的ImageView设置为简单适配器列表?,android,listview,picasso,Android,Listview,Picasso,我想使用毕加索将图像设置为我的简单适配器ListView,我尝试了下面的代码,但它在日志中显示错误为“java.lang.IllegalArgumentException:Target不能为null”。那么我该如何做呢 //MainActivity.java StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL, new Response.Listener

我想使用毕加索将图像设置为我的简单适配器ListView,我尝试了下面的代码,但它在日志中显示错误为“java.lang.IllegalArgumentException:Target不能为null”。那么我该如何做呢

//MainActivity.java

StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
                new Response.Listener<String>() {

                    @Override
                    public void onResponse(String response) {

                        try {

                            JSONObject jsonObj = new JSONObject(response);
                            //Log.e(response,"sdsa");
                            // Getting JSON Array node

                            int iserror = jsonObj.getInt("error");
//                            Toast.makeText(MainActivity.this,iserror,Toast.LENGTH_LONG).show();

                            if (iserror == 1) {
                                String error_msg = jsonObj.getString("result");
                                Toast.makeText(Earn.this,error_msg,Toast.LENGTH_LONG).show();
                            }

                            JSONArray result = jsonObj.getJSONArray("result");
    for (int j = 0; j < result.length(); j++) {

                                        JSONObject apps_applist = result.getJSONObject(j);

                                         iddstr = apps_applist.getString("id");
                                         namestr = apps_applist.getString("name");
                                         logostr=apps_applist.getString("logo");


                                        HashMap<String, String> contact = new HashMap<>();

                                        // adding each child node to HashMap key => value
                                        contact.put("id", iddstr);
                                        contact.put("name", namestr);
                                        contact.put("logo", logostr);

                                        Picasso.with(Earn.this)
                                                .load(logostr)
                                                // .placeholder(R.drawable.placeholder)   // optional
                                                //.error(R.drawable.error)      // optional
                                                .resize(400,400)                        // optional
                                                .into((ImageView) findViewById(R.id.Img_Logo));
                                        // adding contact to contact list
                                        contactList.add(contact);

                                    }
                         ListAdapter adapter = new SimpleAdapter(Earn.this, contactList,
                                        R.layout.list_earn, new String[]{ "name","id","logo"},
                                        new int[]{R.id.textView24, R.id.textView23, R.id.Img_Logo});
                                lv.setAdapter(adapter);
StringRequest StringRequest=新的StringRequest(Request.Method.POST,REGISTER\u URL,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
试一试{
JSONObject jsonObj=新的JSONObject(响应);
//Log.e(答复“sdsa”);
//获取JSON数组节点
int-iserror=jsonObj.getInt(“错误”);
//Toast.makeText(MainActivity.this,iserror,Toast.LENGTH_LONG.show();
如果(iserror==1){
字符串错误_msg=jsonObj.getString(“结果”);
Toast.makeText(Earn.this,error_msg,Toast.LENGTH_LONG).show();
}
JSONArray result=jsonObj.getJSONArray(“结果”);
对于(int j=0;jvalue
联系人。输入(“id”,iddstr);
联系人。填写(“姓名”,名称TR);
联系人。放置(“logo”,logostr);
毕加索。用(赚这个)
.load(logostr)
//.placeholder(R.drawable.placeholder)//可选
//.error(R.drawable.error)//可选
.resize(400400)//可选
.into((ImageView)findViewById(R.id.Img_徽标));
//将联系人添加到联系人列表
联系人列表。添加(联系人);
}
ListAdapter=新的SimpleAdapter(Earn.this,contactList,
R.layout.list_earn,新字符串[]{“name”,“id”,“logo”},
新的int[]{R.id.textView24,R.id.textView23,R.id.Img_Logo});
低压设置适配器(适配器);
//list_earn.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.15">


        <ImageView
            android:layout_width="113dp"
            android:layout_height="107dp"
            app:srcCompat="@mipmap/ic_launcher"
            android:id="@+id/Img_Logo" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView23"
        android:layout_weight="1"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:id="@+id/textView24"
        android:layout_below="@+id/textView23"
        android:layout_alignLeft="@+id/textView23"
        android:layout_alignStart="@+id/textView23"
        android:layout_marginTop="23dp" />

    <Button
        android:text="Button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button4"
        android:background="@drawable/button_format"
        android:layout_below="@+id/Img_Logo"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="31dp" />


</RelativeLayout>

</LinearLayout>

//activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin">


    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>


您定义了img\u视图?请发布更多代码。一些错误日志是..它位于logostr的顶部检查值上。它可能为null。是的,它为null…我不知道它是如何为null的?您定义了img\u视图?请发布更多代码。一些错误日志是..它位于logostr的顶部检查值上。它可能为null。是的,它为null…我不知道它是如何为null的?