element of string contains null

Possible Solution 当我写这样的 xNames[index] = String.valueOf(cA.getXName()); 结果为null .

但是当我写这样的时候 xNames[index] = cA.getXName(); 我的应用程序崩溃了 .

this my snippet code

/* count is total children under Attendance
                 * ref = db.getReference("Attendance")
                 */
                int count = (int) dataSnapshot.getChildrenCount();

                //specify array length using count
                int[] xValues = new int[count];
                int[] yValues = new int[count];
                String[] xNames = new String[count];

                /*
                 * inserting value into xNames, xValues and yValues
                 * ------------------------------------------------
                 */

                // index number start from zero
                int index = 0;

                // get all children under Attendance and insert it into myDatabases
                for (DataSnapshot myDatabases : dataSnapshot.getChildren()) {

                    // myDatabases brings all values from class of Current Attendance
                    CurrentAttendance cA = myDatabases.getValue(CurrentAttendance.class);

                    // if cA is not empty
                    if (cA != null) {

                        /*Coba Integer.valueOf(cA.getUserCount()); apakah null ?*/

                        //insert value of 'cA.getXName' into xNames[index]
                        xNames[index] = String.valueOf(cA.getXName());
                        xValues[index] = cA.getUserCount();
                    }

                    if (cA != null) {
                        yValues[index] = cA.getCurrentAttendance();
                    }

                    // index number increase when this block successfully executed
                    index++;
                }

                ArrayList<BarEntry> barEntry = new ArrayList<BarEntry>();
                for (int i = 0; i < xValues.length; i++)
                    barEntry.add(new BarEntry(xValues[i], yValues[i]));


                BarDataSet set1 = new BarDataSet(barEntry, "Attendance");
                set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
                set1.setDrawValues(false);

                ArrayList<IBarDataSet> dataSets = new ArrayList<>();
                dataSets.add(set1);

                BarData data = new BarData(dataSets);

                XAxis xAxis = barChart.getXAxis();
                xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
                xAxis.setGranularity(1.0f);

                List<String> xListNames = new ArrayList<String>();
                for (int n = 0; n < xValues.length; n++)
                    xListNames.add(xNames[n]);

                String[] names = xListNames.toArray(new String[count]);


                xAxis.setValueFormatter(new MyXAxisValueFormatter(names));

                barChart.getAxisRight().setEnabled(false);
                barChart.setScaleEnabled(true);
                barChart.setPinchZoom(true);
                barChart.setDoubleTapToZoomEnabled(false);
                barChart.setDragEnabled(true);

                barChart.setData(data);

                //zooms out to original size
                barChart.resetZoom();

                //refresh chart
                barChart.invalidate();
            }