有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓 java。lang.NullPointerException:尝试调用虚拟方法。请告诉我修复方法,并尝试所有解决方案

*其他人也有类似的错误,尽管这一个不同。请让我知道如何解决此问题。我在上一次应用程序更新中没有更改代码,它运行得很好。我昨天生成了一个已签名的apk,现在应用程序似乎崩溃了

public class HistoryItem extends RecyclerView.Adapter<HistoryItem.ItemRowHolder> {

    private List<AllTransaksiModel> dataList;
    private Context mContext;
    private int rowLayout;


    public HistoryItem(Context context, List<AllTransaksiModel> dataList, int rowLayout) {
        this.dataList = dataList;
        this.mContext = context;
        this.rowLayout = rowLayout;

    }


    @NonNull
    @Override
    public ItemRowHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(rowLayout, parent, false);
        return new ItemRowHolder(v);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull final ItemRowHolder holder, final int position) {
        final AllTransaksiModel singleItem = dataList.get(position);
        holder.text.setText("Order " + singleItem.getFitur());
        if (singleItem.getHome().equals("4")) {
            double totalbiaya = Double.parseDouble(singleItem.getTotalbiaya());
            Utility.currencyTXT(holder.nominal, String.valueOf(singleItem.getHarga()+ totalbiaya), mContext);
        } else {
            Utility.currencyTXT(holder.nominal, String.valueOf(singleItem.getHarga()), mContext);
        }
        holder.keterangan.setText(singleItem.getStatustransaksi());


        SimpleDateFormat timeFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
        String finalDate = timeFormat.format(singleItem.getWaktuOrder());
        holder.tanggal.setText(finalDate);

        PicassoTrustAll.getInstance(mContext)
                .load(Constants.IMAGESFITUR + singleItem.getIcon())
                .into(holder.images);

        if (singleItem.status == 4 && singleItem.getRate().isEmpty()) {
            holder.keterangan.setTextColor(mContext.getResources().getColor(R.color.black));
            holder.nominal.setTextColor(mContext.getResources().getColor(R.color.colorgradient));
            holder.background.setBackground(mContext.getResources().getDrawable(R.drawable.btn_rect));

        } else if (singleItem.status == 5) {
            holder.keterangan.setTextColor(mContext.getResources().getColor(R.color.red));
            holder.nominal.setTextColor(mContext.getResources().getColor(R.color.red));
            holder.background.setBackground(mContext.getResources().getDrawable(R.drawable.btn_rect_red));

        } else {
            holder.keterangan.setTextColor(mContext.getResources().getColor(R.color.black));
            holder.nominal.setTextColor(mContext.getResources().getColor(R.color.colorgradient));
            holder.background.setBackground(mContext.getResources().getDrawable(R.drawable.btn_rect));

        }
        holder.itemlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(mContext, OrderDetailActivity.class);
                i.putExtra("id_pelanggan", singleItem.getIdPelanggan());
                i.putExtra("id_transaksi", singleItem.getIdTransaksi());
                i.putExtra("response", String.valueOf(singleItem.status));
                i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                mContext.startActivity(i);
            }
        });


    }

    @Override
    public int getItemCount() {
        return (null != dataList ? dataList.size() : 0);
    }

    static class ItemRowHolder extends RecyclerView.ViewHolder {
        TextView text, tanggal, nominal, keterangan;
        ImageView background, images;
        RelativeLayout itemlayout;

        ItemRowHolder(View itemView) {
            super(itemView);
            background = itemView.findViewById(R.id.background);
            images = itemView.findViewById(R.id.image);
            text = itemView.findViewById(R.id.text);
            tanggal = itemView.findViewById(R.id.texttanggal);
            nominal = itemView.findViewById(R.id.price);
            keterangan = itemView.findViewById(R.id.textket);
            itemlayout = itemView.findViewById(R.id.mainlayout);
        }
    }


}

这是日志猫

020-10-31 14:40:33.423 2516-3062/com.uptask.driverapp E/BufferQueueProducer: [SurfaceTexture-0-2516-0] disconnect: not connected (req=1)
2020-10-31 14:40:34.242 2516-2516/com.uptask.driverapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.uptask.driverapp, PID: 2516
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
        at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
        at java.lang.Double.parseDouble(Double.java:538)
        at com.uptask.driverapp.item.HistoryItem.onBindViewHolder(HistoryItem.java:59)
        at com.uptask.driverapp.item.HistoryItem.onBindViewHolder(HistoryItem.java:31)
        at 安卓x.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
        at 安卓x.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
        at 安卓x.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
        at 安卓x.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
        at 安卓x.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at 安卓x.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at 安卓x.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
        at 安卓x.recyclerview.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:561)
        at 安卓x.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
        at 安卓x.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
        at 安卓x.recyclerview.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
        at 安卓x.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
        at 安卓x.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
        at 安卓x.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
        at 安卓.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
        at 安卓.widget.LinearLayout.onLayout(LinearLayout.java:1565)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at 安卓.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at 安卓.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at 安卓.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at 安卓.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
        at 安卓.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
        at 安卓.widget.LinearLayout.onLayout(LinearLayout.java:1565)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at 安卓.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
2020-10-31 14:40:34.243 2516-2516/com.uptask.driverapp E/AndroidRuntime:     at 安卓.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
        at 安卓.widget.LinearLayout.onLayout(LinearLayout.java:1565)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at 安卓.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at com.安卓.internal.policy.DecorView.onLayout(DecorView.java:1067)
        at 安卓.view.View.layout(View.java:22415)
        at 安卓.view.ViewGroup.layout(ViewGroup.java:6594)
        at 安卓.view.ViewRootImpl.performLayout(ViewRootImpl.java:3427)
        at 安卓.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2894)
        at 安卓.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1942)
        at 安卓.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8595)
        at 安卓.view.Choreographer$CallbackRecord.run(Choreographer.java:988)
        at 安卓.view.Choreographer.doCallbacks(Choreographer.java:765)
        at 安卓.view.Choreographer.doFrame(Choreographer.java:700)
        at 安卓.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
        at 安卓.os.Handler.handleCallback(Handler.java:873)
        at 安卓.os.Handler.dispatchMessage(Handler.java:99)
        at 安卓.os.Looper.loop(Looper.java:214)
        at 安卓.app.ActivityThread.main(ActivityThread.java:7156)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.安卓.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:975)

我已经尝试了所有关于堆栈溢出的解决方案,但我的应用程序似乎仍然崩溃


共 (0) 个答案