Click here to Skip to main content
15,567,466 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
  1  /*
  2   * To change this license header, choose License Headers in Project Properties.
  3   * To change this template file, choose Tools | Templates
  4   * and open the template in the editor.
  5   */
  6  
  7  /**
  8   *
  9   * @author Imalsha
 10   */
 11  public class loging extends javax.swing.JFrame {
 12  
 13      /**
 14       * Creates new form loging
 15       */
 16      public loging() {
 17          initComponents();
 18      }
 19  
 20      /**
 21       * This method is called from within the constructor to initialize the form.
 22       * WARNING: Do NOT modify this code. The content of this method is always
 23       * regenerated by the Form Editor.
 24       */
 25      @SuppressWarnings("unchecked")
 26      // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 27      private void initComponents() {
 28  
 29          jLabel1 = new javax.swing.JLabel();
 30          jLabel2 = new javax.swing.JLabel();
 31          jTextField1 = new javax.swing.JTextField();
 32          jPasswordField1 = new javax.swing.JPasswordField();
 33          jButton1 = new javax.swing.JButton();
 34          jButton2 = new javax.swing.JButton();
 35          jLabel3 = new javax.swing.JLabel();
 36  
 37          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 38          setFont(new java.awt.Font("Calisto MT", 1, 14)); // NOI18N
 39          setUndecorated(true);
 40          getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
 41  
 42          jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 43          jLabel1.setText("User Name:");
 44          getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 250, 126, 20));
 45  
 46          jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 47          jLabel2.setText("Password:");
 48          getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 300, 118, 34));
 49  
 50          jTextField1.addActionListener(new java.awt.event.ActionListener() {
 51              public void actionPerformed(java.awt.event.ActionEvent evt) {
 52                  jTextField1ActionPerformed(evt);
 53              }
 54          });
 55          getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 250, 237, -1));
 56  
 57          jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
 58              public void actionPerformed(java.awt.event.ActionEvent evt) {
 59                  jPasswordField1ActionPerformed(evt);
 60              }
 61          });
 62          getContentPane().add(jPasswordField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 310, 237, -1));
 63  
 64          jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 65          jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/login.png"))); // NOI18N
 66          jButton1.setText("Login");
 67          jButton1.addActionListener(new java.awt.event.ActionListener() {
 68              public void actionPerformed(java.awt.event.ActionEvent evt) {
 69                  jButton1ActionPerformed(evt);
 70              }
 71          });
 72          getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 400, 107, -1));
 73  
 74          jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 75          jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png"))); // NOI18N
 76          jButton2.setText("Clear");
 77          jButton2.addActionListener(new java.awt.event.ActionListener() {
 78              public void actionPerformed(java.awt.event.ActionEvent evt) {
 79                  jButton2ActionPerformed(evt);
 80              }
 81          });
 82          getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(770, 400, 100, -1));
 83  
 84          jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/login Background final.PNG"))); // NOI18N
 85          jLabel3.setText("jLabel3");
 86          getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(-20, 0, -1, -1));
 87  
 88          pack();
 89      }// </editor-fold>                        
 90  
 91      private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
 92          // TODO add your handling code here:
 93      }                                           
 94  
 95      private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
 96          // TODO add your handling code here:
 97      }                                               
 98  
 99      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
100          // TODO add your handling code here:
101      }                                        
102  
103      private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
104          // TODO add your handling code here:
105      }                                        
106  
107      /**
108       * @param args the command line arguments
109       */
110      public static void main(String args[]) {
111          /* Set the Nimbus look and feel */
112          //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
113          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
114           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
115           */
116          try {
117              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
118                  if ("Nimbus".equals(info.getName())) {
119                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
120                      break;
121                  }
122              }
123          } catch (ClassNotFoundException ex) {
124              java.util.logging.Logger.getLogger(loging.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
125          } catch (InstantiationException ex) {
126              java.util.logging.Logger.getLogger(loging.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
127          } catch (IllegalAccessException ex) {
128              java.util.logging.Logger.getLogger(loging.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
129          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
130              java.util.logging.Logger.getLogger(loging.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
131          }
132          //</editor-fold>
133  
134          /* Create and display the form */
135          java.awt.EventQueue.invokeLater(new Runnable() {
136              public void run() {
137                  new loging().setVisible(true);
138              }
139          });
140      }
141  
142      // Variables declaration - do not modify                     
143      private javax.swing.JButton jButton1;
144      private javax.swing.JButton jButton2;
145      private javax.swing.JLabel jLabel1;
146      private javax.swing.JLabel jLabel2;
147      private javax.swing.JLabel jLabel3;
148      private javax.swing.JPasswordField jPasswordField1;
149      private javax.swing.JTextField jTextField1;
150      // End of variables declaration                   
151  }


----------------< com.mycompany:HostelManagementsystem >----------------
Building HostelManagementsystem 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------

--- exec-maven-plugin:3.0.0:exec (default-cli) @ HostelManagementsystem ---
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
	at loging.initComponents(loging.java:65)
	at loging.<init>(loging.java:17)
	at loging$5.run(loging.java:137)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  2.539 s
Finished at: 2021-05-31T21:04:36-07:00


What I have tried:

I tried stackover flower and you tube.
Posted
Updated 31-May-21 6:47am
v2

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 Visual Studio will help you here. Run your program in the debugger and when it fails, VS 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, VS 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
 
Comments
Imalsha Madushani 1-Jun-21 4:03am    
Thank you so much i run in the cmd there was eight erros. I import absolute library also it doesn't work.
loging.java:40: error: package org.netbeans.lib.awtextra does not exist
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
^
loging.java:44: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 250, 126, 20));
^
loging.java:48: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 300, 118, 34));
^
loging.java:55: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 250, 237, -1));
^
loging.java:62: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jPasswordField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 310, 237, -1));
^
loging.java:72: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 400, 107, -1));
^
loging.java:82: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(770, 400, 100, -1));
^
loging.java:85: error: package org.netbeans.lib.awtextra does not exist
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(-10, 0, -1, -1));
^
8 errors
OriginalGriff 1-Jun-21 4:21am    
So use the debugger and look at exactly what is happening!
We can't do that for you: we can't run your code under exactly the same condition that you do!
The error message states that the last line of your program was:
65          jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/login.png"))); // NOI18N

which suggests that the call to getResource failed. Check that the path /login.png is correct, with the debugger.
 
Share this answer
 
Comments
Imalsha Madushani 1-Jun-21 3:04am    
Thank you very much for supporting.but I can't change the path can you help me how to change path? I browsed in google but they were don't work.
Richard MacCutchan 1-Jun-21 3:20am    
I did not tell you to change the path. I suggested that you use the debugger to establish whether it is correct or not. Start by reading the documentation at Class (Java Platform SE 7 )[^], which explains the syntax of the path string. Then compare that with what you have, and the location of your resource at run time.
Imalsha Madushani 1-Jun-21 4:06am    
ok i will try thank you so much!

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