Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    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!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,549
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    The stack trace of the error message that you posted only shows Java classes. If you keep reading down the full error message you will eventually see a class that you have written and a line number. This is where your NPE is happening.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    Hey, thanks for the reply. But this is the full stack of error message that I get. This is why I am having trouble in identifying the problem area.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,549
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    No it is not the full error message. As I said somewhere further down in the stacktrace it will mention one or more of your classes. How are you compiling the code?
    Improving the world one idiot at a time!

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    I can't attempt to compile this code because the imports and some other classes are missing..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    I'm currently using Eclipse to compile my code. Unfortunately this is really what I get from the error messages, all stated error at (Unknown Source). And yes, some classes are missing because I'm working with a customized environment, and I'm making use of the event log imports (thus the Public JSplitPane CreateCostPerResourceReport(PluginContext context, XLog log)).

  7. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    Oh I forgot to mention. Sometimes the compilation works, and sometimes it doesn't (50:50 chance). No error message were generated when it compiles successfully, whereas the above stated error message displayed when it failed to compile.

  8. #8
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Re: "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

    This seems to be a JVM internal bug, either something wrong with JVM or Java native class' internal implementation. I frequently encounter this error when my matlab GUI, Eclipse Java and IE are running simultaneously. Sometimes, matlab GUI gives the following error:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.mathworks.mlwidgets.explorer.DocumentTableColu mns$11.compare(DocumentTableColumns.java:204)
    at com.mathworks.mlwidgets.explorer.DocumentTableColu mns$11.compare(DocumentTableColumns.java:202)
    at com.mathworks.mlwidgets.explorer.DocumentTableUtil s$2.compare(DocumentTableUtils.java:59)
    at com.mathworks.mlwidgets.explorer.DocumentTableUtil s$2.compare(DocumentTableUtils.java:57)
    at com.mathworks.mlwidgets.explorer.DocumentTableUtil s$1.compare(DocumentTableUtils.java:43)
    at com.mathworks.mlwidgets.explorer.DocumentTableUtil s$1.compare(DocumentTableUtils.java:36)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.mergeSort(Unknown Source)
    at java.util.Arrays.sort(Unknown Source)
    at java.util.Collections.sort(Unknown Source)
    at com.mathworks.widgets.grouptable.GroupingTableMode l$17.run(GroupingTableModel.java:737)
    at com.mathworks.widgets.grouptable.GroupingTableMode l$20.run(GroupingTableModel.java:929)
    at com.mathworks.mwswing.MJUtilities.runOnEventDispat chThread(MJUtilities.java:823)
    at com.mathworks.widgets.grouptable.GroupingTableMode l.runAndPreserveSelection(GroupingTableModel.java: 923)
    at com.mathworks.widgets.grouptable.GroupingTableMode l.sort(GroupingTableModel.java:721)
    at com.mathworks.widgets.grouptable.GroupingTable$3.m ouseClicked(GroupingTable.java:239)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(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)

    No matter how I close all programs which uses java (including explorer.exe), restart matlab, etc., it doesn't work. The only solution is to reboot or re-login your OS and everything works again.

Similar Threads

  1. Exception in thread "main" java.lang.NullPointerException
    By Tsark in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 11th, 2011, 08:39 AM
  2. Exception in thread "main" java.lang.NullPointerException
    By MryJaho in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 4th, 2011, 04:36 PM
  3. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  4. Please help! Exception in thread "main" java.lang.NullPointerException
    By Arutha2321 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 18th, 2009, 01:25 AM
  5. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 10:46 PM