public class Tab1 extends Fragment {
ArrayList<BarEntry> bargroup2;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab1, container, false);
HorizontalBarChart barChart = (HorizontalBarChart)rootView.findViewById(R.id.barchartnew);
// create BarEntry for Bar Group 2
bargroup2 = new ArrayList<>();
// creating dataset for Bar Group2
BarDataSet barDataSet2 = new BarDataSet(bargroup2, "Week 2");
//barDataSet2.setColors(ColorTemplate.COLORFUL_COLORS);
barDataSet2.setColor(Color.rgb(100, 50, 10));
ArrayList<String> labels = new ArrayList<String>();
labels.add("December");
labels.add("November");
labels.add("October");
ArrayList<BarDataSet> dataSets = new ArrayList<>(); // combined all dataset into an arraylist
dataSets.add(barDataSet2);
// initialize the Bardata with argument labels and dataSet
BarData data = new BarData(labels, dataSets);
barChart.setData(data);
test("7");
return rootView;
}
public void test(String time){
String f = "f";
Float timefFloat = Float.parseFloat(time + f);
bargroup2.add(new BarEntry(timefFloat, 1));
}
当我从同一个类调用此方法时,它成功地将BarEntry添加到我的bargroup2
数组列表中,该列表将数据添加到我的MPAndroidChart。
然而,当我从一个单独的类调用此方法时,它会导致我的应用停止。我怎样才能解决这个问题?