Hi,
I am getting a "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error in my code. I've been trying to find out where does it goes wrong but I haven't had any solution so far. Can I have some help here? The error message and my code are stated below:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicSplitPaneUI.paint(Unkn own Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubl eBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unkn own Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Un known Source)
at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
public class CreateResourceCostReport extends JPanel implements ActionListener { private static final long serialVersionUID = 1L; static Map<String, Double> mpCostPerTraceMap = new HashMap<String, Double>(); static Map<String, Double> mpCostPerResourceMap = new HashMap<String, Double>(); static Map<String, Double> mpCostPerTraceAndResourceMap = new HashMap<String, Double>(); static String strLogCurrency = null; JSplitPane jspOverallPanel = new JSplitPane(); JPanel jpDisplayPanel = new JPanel(); JPanel jpOptionPanel = new JPanel(); JScrollPane jspDisplayScrollPane = new JScrollPane(); Document dcDisplayDocument = null; JLabel jlChartInfo = new JLabel(); JComboBox jcbChartInfo = new JComboBox(); JLabel jlEmptyLabel = new JLabel(); JLabel jlChartType = new JLabel(); JComboBox jcbChartType = new JComboBox(); boolean blScrollPane = false; public void GenerateResourceCostPerTraceReport (PluginContext context, XLog log) { XConceptExtension xceConceptExt = XConceptExtension.instance(); Double dblTotal = 0.00; Double dblTotalPerResource = 0.00; String strResourceName = null; for (XTrace trace : log) { for (XEvent event : trace) { String strTraceID = xceConceptExt.extractName(trace); Collection<XAttribute> cltAttributes = event.getAttributes().values(); Double dblCost = 0.00; boolean blResource = false; boolean blCost = false; for (XAttribute attribute : cltAttributes) { String strCostTypePrefix = "cost:type"; String strResourcePrefix = "org:resource"; if (attribute.getKey().startsWith("cost:currency")) { strLogCurrency = ((XAttributeLiteral) attribute).getValue(); } if (attribute.getKey().startsWith(strResourcePrefix)) { strResourceName = ((XAttributeLiteral) attribute).getValue(); blResource = true; } if (attribute.getKey().startsWith(strCostTypePrefix)) { dblCost = ((XAttributeContinuous) attribute).getValue(); blCost = true; } } if (blResource == true && blCost == true) { Double dblTotalPerTrace = mpCostPerTraceMap.get(strTraceID); dblTotalPerResource = mpCostPerResourceMap.get(strResourceName); String strTraceIDResourceType = strTraceID + "\t" + strResourceName; Double dblTotalPerTraceAndResource = mpCostPerTraceAndResourceMap.get(strTraceIDResourceType); if (dblTotalPerTrace == null) mpCostPerTraceMap.put(strTraceID, dblCost); else mpCostPerTraceMap.put(strTraceID, dblTotalPerTrace + dblCost); if (dblTotalPerResource == null) mpCostPerResourceMap.put(strResourceName, dblCost); else mpCostPerResourceMap.put(strResourceName, dblTotalPerResource += dblCost); if (dblTotalPerTraceAndResource == null) mpCostPerTraceAndResourceMap.put(strTraceIDResourceType, dblCost); else mpCostPerTraceAndResourceMap.put(strTraceIDResourceType, dblTotalPerTraceAndResource + dblCost); dblTotal += dblCost; blCost = false; blResource = false; } blResource = false; } } } private void GenerateDisplay() { jspOverallPanel = new JSplitPane(); jpOptionPanel = new JPanel(); jlChartInfo = new JLabel("Measure:"); String[] strChartInfo = {"Cost per Resource", "Cost per Trace", "Cost per Task per Trace", "Cost per Resource per Trace"}; jcbChartInfo = new JComboBox(strChartInfo); jlEmptyLabel = new JLabel(""); jlChartType = new JLabel("Chart Type:"); String[] strChartType = {"2D Pie Chart", "3D Pie Chart", "2D Bar Chart", "3D Bar Chart", "Waterfall Chart", "Multiple Bar Chart"}; jcbChartType = new JComboBox(strChartType); GridLayout glGridLayout = new GridLayout(30,1); jpOptionPanel.setLayout(glGridLayout); jpOptionPanel.add(jlChartInfo); jpOptionPanel.add(jcbChartInfo); jpOptionPanel.add(jlEmptyLabel); jpOptionPanel.add(jlChartType); jpOptionPanel.add(jcbChartType); } private JSplitPane Display(JPanel result) { GenerateDisplay(); jcbChartType.addActionListener(this); jpDisplayPanel = result; jspOverallPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jpOptionPanel, jpDisplayPanel); jspOverallPanel.setDividerLocation(200); jspOverallPanel.setDividerSize(3); setLayout(new BorderLayout()); this.add(jspOverallPanel, BorderLayout.CENTER); this.repaint(); this.revalidate(); return jspOverallPanel; } private static JPanel CostReportPieChart2D() { JPanel pnlCostPanel = new JPanel(); String[] strResource; Double[] dblCost; DefaultPieDataset pdPieData = new DefaultPieDataset(); int intCount = 0; List<Entry<String, Double>> list = new ArrayList<Entry<String, Double>>(mpCostPerResourceMap.entrySet()); Collections.sort(list, new StringMapComparator()); strResource = new String[list.size()]; dblCost = new Double[list.size()]; for (Entry<String, Double> entry : list) { strResource[intCount] = entry.getKey(); dblCost[intCount] = roundDouble(entry.getValue(),2); pdPieData.setValue(strResource[intCount] + " = " + dblCost[intCount].toString(), dblCost[intCount]); intCount += 1; } JFreeChart jfcPieChart2D = ChartFactory.createPieChart( "Resource Consumption Cost", pdPieData, true, true, false ); PiePlot plot = (PiePlot) jfcPieChart2D.getPlot(); plot.setNoDataMessage("No data to display"); ChartPanel cpDisplay = new ChartPanel(jfcPieChart2D); cpDisplay.setPreferredSize(new java.awt.Dimension(50, 27)); cpDisplay.setVisible(true); pnlCostPanel = cpDisplay; return pnlCostPanel; } Public JSplitPane CreateCostPerResourceReport(PluginContext context, XLog log) { GenerateResourceCostPerTraceReport(context, log); return Display(CostReportPieChart2D()); }
Thanks in advance!