我有一个带有字符串和 tupleList 的地图。我正在尝试将 tupleList 转换为双数组,但我遇到了类型转换异常。我的代码是——
Map<String, TupleList> results = null; -- Some data in it and TupleList has int or double value.
公共无效drawGraph(){
Object[] test = new Object[results.size()];
int index = 0;
for (Entry<String, TupleList> mapEntry : results.entrySet()) {
test[index] = mapEntry.getValue();
index++;
}
BarChart chart = new BarChart();
chart.setSampleCount(4);
String[] values = new String[test.length];
for(int i = 0; i < test.length; i++)
{
values[i] = (String) test[i];
}
// double[] values = new double[] {32,32,65,65};
String[] sampleLabels = new String[] {"deny\nstatus", "TCP\nrequest", "UPD\nrequest", "ICMP\nrequest"};
String[] barLabels = new String[] {"STATUS", "TCP", "UDP", "PING"};
//chart.setSampleValues(0, values);
chart.setSampleColor(0, new Color(0xFFA000));
chart.setRange(0, 88);
chart.setFont("rangeLabelFont", new Font("Arial", Font.BOLD, 13));
错误 - -
java.lang.ClassCastException: somePackagename.datamodel.TupleList cannot be cast to java.lang.String
at com.ibm.biginsights.ExampleAPI.drawGraph(ExampleAPI.java:177)
at com.ibm.biginsights.ExampleAPI.main(ExampleAPI.java:95)
我得到了例外@
String[] values = new String[test.length];
for(int i = 0; i < test.length; i++)
{
values[i] = (String) test[i];
谢谢