【发布时间】:2021-07-24 02:21:43
【问题描述】:
decibelChart.postDelayed(new Runnable() {
@Override
public void run() {
int chartValue;
decibelChart.setNoDataText("Drawing Decibel Chart Error !");
decibelChart.setDragEnabled(false);
decibelChart.setScaleEnabled(false);
decibelChart.setDrawGridBackground(false);
decibelChart.setPinchZoom(false);
decibelChart.setBackgroundColor(Color.TRANSPARENT);
decibelChart.setData(lineData);
if (mediaRecorderForDB != null) {
chartValue = mediaRecorderForDB.getMaxAmplitude();
} else if (mediaRecorder != null) {
chartValue = mediaRecorder.getMaxAmplitude();
} else
chartValue = 0;
LineData myData = decibelChart.getData();
if (myData != null) {
ILineDataSet set = myData.getDataSetByIndex(0);
if (set == null){
LineDataSet dataSet = new LineDataSet(null,"Dynamic");
dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
dataSet.setLineWidth(3f);
dataSet.setColor(Color.WHITE);
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
dataSet.setCubicIntensity(1f);
myData.addDataSet(dataSet);
}
myData.addEntry(new Entry(set.getEntryCount(), chartValue + 5), 0);
myData.notifyDataChanged();
decibelChart.setMaxVisibleValueCount(150);
decibelChart.moveViewToX(myData.getEntryCount());
}
Log.e("[CHART_ERROR]", "CHART DRAWING");
}
},250);
set.getEntryCount() 返回 null 并抛出异常。我怎样才能克服它?我尝试了很多东西,但无法实现。
这些值来自麦克风,它们是分贝值。我想为这些值绘制折线图。
【问题讨论】:
-
你有
ILineDataSet set = myData.getDataSetByIndex(0);,然后是if (set == null),但如果它为 null,你永远不会改变set的值,那么为什么不会它仍然是空的 -
不,它没有回答我的问题。仍然需要帮助。
-
您是否阅读了我的第一条评论,您对此有何回应?
-
请撤消您的编辑,以便下面的答案有意义。你仍然需要你的问题来帮助未来的人。
-
我已经按照@NomadMaker 的建议进行了回滚,请考虑这样一个事实,即这个社区不仅仅是为了帮助你,它也是为了未来的人们以及遇到同样问题的人