Click here to Skip to main content
15,562,015 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
  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;
  9  
 10  
 11  /**
 12   *
 13   * @author Patali
 14   */
 15  public class Main_GUI extends javax.swing.JFrame {
 16  
 17      /**
 18       * Creates new form Main_GUI
 19       */
 20      public Main_GUI() {
 21          initComponents();
 22      }
 23      
 24      void rebindTable1(List stuList)
 25     
 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      }

.......................
Java
  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);
 16          
 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(Main_GUI.java:487)
	at App.Main_GUI.access$600(Main_GUI.java:22)
	at App.Main_GUI$7.actionPerformed(Main_GUI.java:194)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
	at java.awt.Component.processMouseEvent(Component.java:6539)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
	at java.awt.Component.processEvent(Component.java:6304)
	at java.awt.Container.processEvent(Container.java:2239)
	at java.awt.Component.dispatchEventImpl(Component.java:4889)
	at java.awt.Container.dispatchEventImpl(Container.java:2297)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
	at java.awt.Container.dispatchEventImpl(Container.java:2283)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
	at java.awt.EventQueue$4.run(EventQueue.java:733)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Posted
Updated 9-Jul-21 0:37am
v2
Comments
Richard MacCutchan 9-Jul-21 5:38am    
	at App.Main_GUI.jButton5ActionPerformed(Main_GUI.java:487)
	at App.Main_GUI.access$600(Main_GUI.java:22)
	at App.Main_GUI$7.actionPerformed(Main_GUI.java:194)

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