-1

the problem is when I click on cart object to make an order the app crashes and throws the NullPointerExcetion.

my Cart.java code is

public class Cart extends AppCompatActivity {

    RecyclerView recyclerView;
    RecyclerView.LayoutManager layoutManager;

    FirebaseDatabase database;
    DatabaseReference requests;

    TextView txtTotalPrice;
    FButton btnPlace;

    List<Order> cart = new ArrayList<>();
    CartAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cart);

        //Firebase
        database = FirebaseDatabase.getInstance();
        requests = database.getReference("Requests");

            public void onClick(DialogInterface dialogInterface, int i) {
                        Request request = new Request(
                        Common.currentUser.getPhone(),
                        Common.currentUser.getName(),
                        edtAddress.getText().toString(),
                        txtTotalPrice.getText().toString(),
                        cart
                );

                // send it to firebase
                requests.child(String.valueOf(System.currentTimeMillis()))
                        .setValue(request);
                //Delete cart
                new Database(getBaseContext()).cleanCart();
                Toast.makeText(Cart.this, "Thank you, Order is placed!", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    private void loadListFood() {
        cart = new Database(this).getCarts();
        adapter = new CartAdapter(cart, this);
        recyclerView.setAdapter(adapter);
    }
}
seenukarthi
  • 8,241
  • 10
  • 47
  • 68

1 Answers1

0

This suggests that you are trying to access a null object when you are using Common.currentUser. As we cannot see how you define this object variable, it is hard to determine the exact reason it is null.

Luke
  • 130
  • 1
  • 9