android studio写完适配器,我无法在android studio中将适配器附加到recyclerview[副本]

错误:

android.view.InflateException: Binary XML file line #32: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolea

n java.lang.String.equals(java.lang.Object)' on a null object reference

vv = LayoutInflater.from(context).inflate(R.layout.custom_offerpro,parent,false);

public class AmazingproAdapter extends RecyclerView.Adapter {

在适配器中。。

public class AmazingproAdapter extends RecyclerView.Adapter {

List offerpro;

Context context;

View vv;

ProductAmazing Amazingproduct;

ImageView img;

public AmazingproAdapter(List offerpro, Context context) {

this.offerpro = offerpro;

this.context = context;

}

@NonNull

@Override

public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

vv = LayoutInflater.from(context).inflate(R.layout.custom_offerpro,parent,false);

return new PostViewHolder(vv) ;

}

@Override

public void onBindViewHolder(@NonNull PostViewHolder holder, int position) {

Amazingproduct = offerpro.get(position);

holder.txtcaption.setText(Amazingproduct.getCaption());

holder.txtpreprice.setText(String.valueOf(Amazingproduct.getPreprice()));

holder.txtnewprice.setText(String.valueOf(Amazingproduct.getNewprice()));

Picasso.with(context).load(Config.IMAGES_URL + "amazingpro/" + Amazingproduct.getImg()).into(img);

}

@Override

public int getItemCount() {

return offerpro.size();

}

public class PostViewHolder extends RecyclerView.ViewHolder{

TextView txtcaption,txtpreprice,txtnewprice;

public PostViewHolder(View itemView) {

super(itemView);

txtcaption = itemView.findViewById(R.id.offerpro_caption);

txtpreprice = itemView.findViewById(R.id.offerpro_preprice);

txtnewprice = itemView.findViewById(R.id.offerpro_newprice);

img = itemView.findViewById(R.id.offerpro_img);

}

}

}

xml自定义视图:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/card_offerpro"

app:cardElevation="0dp"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:id="@+id/offerpro_img"

android:layout_width="match_parent"

android:layout_height="165dp" />

android:id="@+id/offerpro_caption"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:hint="عÙÙاÙ" />

android:id="@+id/view"

android:layout_width="match_parent"

android:layout_height="0.5dp"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="20dp"

android:background="@color/black" />

android:id="@+id/offerpro_preprice"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="16dp"

android:hint="163.000"

android:textColor="@color/colorPrimary"

android:textSize="16sp"

android:textStyle="bold" />

android:id="@+id/offerpro_newprice"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginEnd="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="12dp"

android:hint="110.000"

android:textColor="@color/black"

android:textStyle="bold" />

main活动.java

private void getamazingdata() {

StringRequest request = new StringRequest(

Config.URL_GETOFFERAMAZING,

new Response.Listener() {

@Override

public void onResponse(String response) {

list = Config.Jsonamazingparser(response);

if(list!=null) {

adapter = new AmazingproAdapter(list, MainActivity.this);

recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));

recyclerView.setAdapter(adapter);

}else{

Toast.makeText(activity, "List is empty", Toast.LENGTH_SHORT).show();

}

}

}, new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError error) {

VolleyLog.d("Amazing offer response is : " , " Error " + error.getMessage());

}

}

);

RequestQueue queue = Volley.newRequestQueue(activity);

queue.add(request);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值