Main和android.graphics.drawable.RippleDrawable

时间:2019-06-17 10:04:46

标签: java android sqlite android-sqlite sqliteopenhelper

我在Viewpager类中滑动时,遇到应用程序中的问题,错误为AndroidRuntime: FATAL EXCEPTION: main。该应用程序在Viewpager和2之间正常运行,但是当我滑动到Viewpager 3时,该应用程序崩溃了。

我在Viewpager类中遇到的错误在这里;在这条线上。

            if (listProduct.get(position).getNAME() != null) {
            holder.lblPName.setText(listProduct.get(position).getNAME());
        }

这是崩溃日志

/com.example.tablewithlist E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
    at com.example.tablewithlist.InvoicesRecyclerAdapter.onBindViewHolder(InvoicesRecyclerAdapter.java:58)
    at com.example.tablewithlist.InvoicesRecyclerAdapter.onBindViewHolder(InvoicesRecyclerAdapter.java:17)

删除此行并运行代码后,我遇到的错误是

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.design.widget.TabLayout$TabView.updateBackgroundDrawable
com.example.tablewithlist E/RecyclerView: No adapter attached; skipping layout
om.example.tablewithlist E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
    at com.example.tablewithlist.InvoicesRecyclerAdapter.onBindViewHolder(InvoicesRecyclerAdapter.java:61)
    at com.example.tablewithlist.InvoicesRecyclerAdapter.onBindViewHolder(InvoicesRecyclerAdapter.java:17)

这次是我删除的行的下一行错误

           if (listProduct.get(position).getRETAIL() != null) {
            holder.lblRetail.setText(listProduct.get(position).getRETAIL());
        }

这是发票回收站适配器

public class InvoicesRecyclerAdapter extends RecyclerView.Adapter<InvoicesRecyclerAdapter.ClientViewHolder> {

private List<GetSetProductsDetail> listProduct;
Context mContext;
RecyclerView mRecyclerView;
View itemView;

public InvoicesRecyclerAdapter(List<GetSetProductsDetail> listProduct, RecyclerView recyclerView) {
    this.listProduct = listProduct;
    mRecyclerView = recyclerView;
}


@Override
public ClientViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    mContext = parent.getContext();
    itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.items_invoice, parent, false);
    return new ClientViewHolder(itemView);
}


public class ClientViewHolder extends RecyclerView.ViewHolder {

    public TextView lblPName;
    public TextView lblRetail;
    RelativeLayout layout;

    public ClientViewHolder(View view) {
        super(view);


        lblPName = view.findViewById(R.id.lblInvoicePName);
        lblRetail = view.findViewById(R.id.lblInvoiceRetail);
        layout = view.findViewById(R.id.listinvoice);
    }
}

@Override
public void onBindViewHolder(ClientViewHolder holder, final int position) {
    if (listProduct != null) {
        if (listProduct.get(position).getNAME() != null) {
            holder.lblPName.setText(listProduct.get(position).getNAME());
        }
        if (listProduct.get(position).getRETAIL() != null) {
            holder.lblRetail.setText(listProduct.get(position).getRETAIL());
        }
        holder.layout.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                displayingAlertDialog(position);
                return false;
            }
        });
    }
}

@Override
public int getItemCount() {
    Log.v(InvoicesRecyclerAdapter.class.getSimpleName(), "" + listProduct.size());
    return listProduct.size();
}

private void displayingAlertDialog(final int position) {
    final GetSetProductsDetail getSetProductsDetail = new GetSetProductsDetail();
    gotoInvoiceClass(listProduct.get(position).getNAME());
}

private void gotoInvoiceClass(String namebltp) {
    MainFragment main = (MainFragment) mContext;
    Toast.makeText(main, "d " + namebltp, Toast.LENGTH_SHORT).show();
    // main.selectTabProd(2, namebltp);

}

}

这是发票类别

public class Invoices extends Fragment {

TextView EdtName;
EditText EditCurrDate;
EditText EdtCurrDate2;
TextView EdtNameProdInvoiuce;
RecyclerView recyclerViewProdInvoice;
InvoicesRecyclerAdapter invoicesRecyclerAdapter;
List<GetSetProductsDetail> listproductsInvoices;
DatabaseHelper databaseHelper;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.invoice, container, false);

    recyclerViewProdInvoice=view.findViewById(R.id.recyclerviewinvoicesprod);

    databaseHelper = new DatabaseHelper(getActivity());

    listproductsInvoices = new ArrayList<>();

    String date_n = new SimpleDateFormat("MMM / dd / yyyy", Locale.getDefault()).format(new Date());

    EditCurrDate = view.findViewById(R.id.currdate);
    EdtCurrDate2 = view.findViewById(R.id.currdate1);
    EdtName = view.findViewById(R.id.txtclientname);
    EdtNameProdInvoiuce = view.findViewById(R.id.edtprodinvoice);

    MainFragment activity = (MainFragment) getActivity();
    String name = activity.getMyData();
    EdtName.setText(name);

    MainFragment activityprodinvoice = (MainFragment) getActivity();
    String namebltp = activityprodinvoice.getMyProdData();
    EdtNameProdInvoiuce.setText(namebltp);

    EdtName.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle("Choose Option");
            builder.setMessage("Are You Sure You Want To Add New Client?");
            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MainFragment main = (MainFragment) getActivity();
                    main.fromThirdToSecond(0);
                    dialog.cancel();

                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            AlertDialog alert11 = builder.create();
            alert11.show();
            return false;
        }
    });

    EditCurrDate.setText(date_n);

    EdtCurrDate2.setText(date_n);

    EditCurrDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar mcurrentDate = Calendar.getInstance();
            int year = mcurrentDate.get(Calendar.YEAR);
            int month = mcurrentDate.get(Calendar.MONTH);
            int day = mcurrentDate.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog mDatePicker = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker datepicker, int selectedYear, int selectedMonth, int selectedDay) {
                    // TODO Auto-generated method stub

                    Log.e("Date Selected", "Month: " + selectedMonth + " Day: " + selectedDay + " Year: " + selectedYear);
                    EditCurrDate.setText((selectedMonth + 1) + "/" + selectedDay + "/" + selectedYear);
                }
            }, year, month, day);
            mDatePicker.setTitle("Select date");
            mDatePicker.show();
        }
    });

    EdtCurrDate2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar mcurrentDate = Calendar.getInstance();
            int year1 = mcurrentDate.get(Calendar.YEAR);
            int month1 = mcurrentDate.get(Calendar.MONTH);
            int day1 = mcurrentDate.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog mDatePicker = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker datepicker, int selectedYear, int selectedMonth, int selectedDay) {
                    // TODO Auto-generated method stub

                    Log.e("Date Selected", "Month: " + selectedMonth + " Day: " + selectedDay + " Year: " + selectedYear);
                    EdtCurrDate2.setText((selectedMonth + 1) + "/" + selectedDay + "/" + selectedYear);
                }
            }, year1, month1, day1);
            mDatePicker.setTitle("Select date");
            mDatePicker.show();
        }
    });
    return view;
}

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isResumed() && isVisibleToUser) {

        MainFragment activity = (MainFragment) getActivity();


        String namebltp = activity.getMyProdData();
        EdtNameProdInvoiuce.setText(namebltp);

        GetSetProductsDetail product = activity.listProduct;
        listproductsInvoices.add(product);

        invoicesRecyclerAdapter = new InvoicesRecyclerAdapter(listproductsInvoices,recyclerViewProdInvoice);
        recyclerViewProdInvoice.setItemAnimator(new DefaultItemAnimator());
        recyclerViewProdInvoice.setItemAnimator(new DefaultItemAnimator());
        recyclerViewProdInvoice.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerViewProdInvoice.setHasFixedSize(true);
        recyclerViewProdInvoice.setAdapter(invoicesRecyclerAdapter);
    }
}

}

1 个答案:

答案 0 :(得分:-1)

检查第17行,您的listProduct可能尚未初始化