Someone please help me with the null pointer exception so basically my idea was to call back the panel itself and it happened to have null point, why? JPanel contentPane = new AnnualPerformancePanel(mf); mf.setContentPane(contentPane); mf.setVisible(true); this few code that causes the problem.
public class AnnualPerformancePanel extends MasterPanel {
public static int yearCon;
public AnnualPerformancePanel(JFrame mf, int yearContainer) {
super(mf);
JPanel ChartPanel = new JPanel();
ChartPanel.setBounds(15, 133, 960, 415);
add(ChartPanel);
yearCon = yearContainer;
JLabel lblAnnualPerformance = new JLabel("Annual Performance");
lblAnnualPerformance.setFont(new Font("Verdana", Font.BOLD, 25));
lblAnnualPerformance.setBounds(362, 71, 304, 32);
add(lblAnnualPerformance);
JLabel lblAnnualStatement = new JLabel("Annual Statement");
lblAnnualStatement.setFont(new Font("Verdana", Font.PLAIN, 15));
lblAnnualStatement.setBounds(15, 109, 146, 20);
add(lblAnnualStatement);
GregorianCalendar calendar = new GregorianCalendar();
int calendarYear = calendar.getTime().getYear() - 100 +2000;
int calendarMonth = calendar.getTime().getMonth();
String[] year = {"2017","2016","2015","2014","2013"};
JComboBox YearFilter = new JComboBox(year);
YearFilter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for(int i =5;i>0;i--){
if(calendarYear == yearContainer){
System.out.println("===++=====");
YearFilter.setSelectedItem(yearContainer);
}
}
}
});
JFreeChart barChart = ChartFactory.createBarChart("","Month","Amount",BarChart_AWT.createDataset(yearContainer),PlotOrientation.VERTICAL,true, true, false);
ChartPanel chartPanel = new ChartPanel( barChart );
chartPanel.setPreferredSize(new java.awt.Dimension( 900 , 400 ) );
ChartPanel.add(chartPanel);
YearFilter.setBounds(162, 109, 82, 20);
add(YearFilter);
YearFilter.setSelectedIndex(calendarMonth);
JLabel lblTotalAmountSpent = new JLabel("Total Amount Spent");
lblTotalAmountSpent.setFont(new Font("Verdana", Font.PLAIN, 15));
lblTotalAmountSpent.setBounds(28, 591, 170, 20);
add(lblTotalAmountSpent);
JLabel lblExceededCreditUsage = new JLabel("Exceeded Credit Usage");
lblExceededCreditUsage.setFont(new Font("Verdana", Font.PLAIN, 15));
lblExceededCreditUsage.setBounds(28, 555, 183, 20);
add(lblExceededCreditUsage);
System.out.println("===================");
JButton btnNewButton = new JButton("Submit");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JPanel contentPane = new AnnualPerformancePanel(mf);
mf.setContentPane(contentPane);
mf.setVisible(true);
}
});
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
btnNewButton.setBounds(259, 109, 107, 20);
add(btnNewButton);
double totalAmount = 0;
ArrayList<Transaction> result = TransactionDA.retrieveAllTransaction();
for(int i =0; i<result.size(); i++){
if(Integer.parseInt(result.get(i).getTransactionDate().substring(6,8)) == calendarYear){
totalAmount += result.get(i).getTransactionAmount();
}
}
}
}
Stack trace
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at AnnualPerformancePanel$2.actionPerformed(AnnualPerformancePanel.java:114)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(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(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown 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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Un known Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)