I have a problem with converting my String into date and it gives me a null pointer exception and I've tried everything.

This is how I enter my String into my database from calendarView

```
mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
        @Override
        public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
            string = (i1 + 1) + "/" +i2 + "/" + i;
}
        });

String key = mDatabase.push().getKey();

                HashMap<String, String> dataMap = new HashMap<>();
                dataMap.put("Date", date);
                dataMap.put("Key", key);
 mDatabase.child(key).setValue(dataMap);

```

Then when I retrieve it from my database I format it like this 

```
databaseReference = FirebaseDatabase.getInstance().getReference().child("Groups").child("JMHyOvgCDvdKEZuReJvdGcExEnX2").child("HomeFragment").child("FreezerItems");
        valueEventListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                HashMap<String, String> value = (HashMap<String,String>) dataSnapshot.getValue();
                if (value != null){
                    String name = value.get("Name");
                    String date = value.get("Date");

                    try {
                        dateFormat = new Date();
                        dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.US).parse(date);

                    } catch (ParseException e) {
                        Log.wtf("FailedtoChangeDate", "Fail");
                    }

```

My problem is when I try to convert the string to M/dd/yyyy format even though the date's format in string is like this "5/30/2018"

A screen shot when I debug it [![](https://i.stack.imgur.com/0qavq.png)](https://i.stack.imgur.com/0qavq.png)