Click here to Skip to main content
15,615,787 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
  1  import java.awt.Image;
  2  import java.awt.Toolkit;
  3  import java.util.ArrayList;
  4  import java.util.List;
  5  import javax.persistence.Query;
  6  import javax.swing.ImageIcon;
  7  import javax.swing.JFileChooser;
  8  import javax.swing.JOptionPane;
 11  /**
 12   *
 13   * @author Patali
 14   */
 15  public class Main_GUI extends javax.swing.JFrame {
 17      /**
 18       * Creates new form Main_GUI
 19       */
 20      public Main_GUI() {
 21          initComponents();
 22      }
 24      void rebindTable1(List stuList)
 26      {
 27      org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, stuList, jTable1);
 28          org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${studentid}"));
 29          columnBinding.setColumnName("Studentid");
 30          columnBinding.setColumnClass(String.class);
 31          columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${sname}"));
 32          columnBinding.setColumnName("Sname");
 33          columnBinding.setColumnClass(String.class);
 34          columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${age}"));
 35          columnBinding.setColumnName("Age");
 36          columnBinding.setColumnClass(Integer.class);
 37          columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${address}"));
 38          columnBinding.setColumnName("Address");
 39          columnBinding.setColumnClass(String.class);
 40          bindingGroup.addBinding(jTableBinding);
 41          jTableBinding.bind();
 42      }

  1  private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  2          List<StuSum> stusumlist=new ArrayList<StuSum>();
  3          int count=0,tot=0;
  4          for(Department d: departmentList){
  5              count=0;
  6              for(Student s: studentList){
  7                  if(s.getDept().getDeptid()==d.getDeptid())
  8                  {
  9                      count++;
 10                      tot++;
 11                  }                    
 12              }
 13              stusumlist.add(new StuSum(d.getDname(), count));
 14          }
 15          jLabel8.setText("Count : "+tot);
 17          org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, stusumlist, jTable2);
 18          org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dname}"));
 19          columnBinding.setColumnName("Department Name");
 20          columnBinding.setColumnClass(String.class);
 21          columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${count}"));
 22          columnBinding.setColumnName("No. of Students");
 23          columnBinding.setColumnClass(Integer.class);
 24          bindingGroup.addBinding(jTableBinding);
 25          jTableBinding.bind();
 26      }

What I have tried:

Actuallly my error is in the jButton5 when i run and click in the jbutton5 i got this error
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at App.Main_GUI.jButton5ActionPerformed(
	at App.Main_GUI.access$600(
	at App.Main_GUI$7.actionPerformed(
	at javax.swing.AbstractButton.fireActionPerformed(
	at javax.swing.AbstractButton$Handler.actionPerformed(
	at javax.swing.DefaultButtonModel.fireActionPerformed(
	at javax.swing.DefaultButtonModel.setPressed(
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
	at java.awt.Component.processMouseEvent(
	at javax.swing.JComponent.processMouseEvent(
	at java.awt.Component.processEvent(
	at java.awt.Container.processEvent(
	at java.awt.Component.dispatchEventImpl(
	at java.awt.Container.dispatchEventImpl(
	at java.awt.Component.dispatchEvent(
	at java.awt.LightweightDispatcher.retargetMouseEvent(
	at java.awt.LightweightDispatcher.processMouseEvent(
	at java.awt.LightweightDispatcher.dispatchEvent(
	at java.awt.Container.dispatchEventImpl(
	at java.awt.Window.dispatchEventImpl(
	at java.awt.Component.dispatchEvent(
	at java.awt.EventQueue.dispatchEventImpl(
	at java.awt.EventQueue.access$500(
	at java.awt.EventQueue$
	at java.awt.EventQueue$
	at Method)
	at java.awt.EventQueue$
	at java.awt.EventQueue$
	at Method)
	at java.awt.EventQueue.dispatchEvent(
	at java.awt.EventDispatchThread.pumpOneEventForFilters(
	at java.awt.EventDispatchThread.pumpEventsForFilter(
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(
	at java.awt.EventDispatchThread.pumpEvents(
	at java.awt.EventDispatchThread.pumpEvents(
Updated 8-Jul-21 23:37pm
Richard MacCutchan 9-Jul-21 5:38am    
	at App.Main_GUI.jButton5ActionPerformed(
	at App.Main_GUI.access$600(
	at App.Main_GUI$7.actionPerformed(

Where are lines 487 and 194?

1 solution

This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.

Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterday's shirt when you took it off last night.

We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!

Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and the debugger will help you here. Run your program in the debugger and when it fails, it will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, the debugger will stop before the error, and let you examine what is going on by stepping through the code looking at your values.

But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900