473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getting err java.lang.NullPointerException

i dont know y im getting this err java.lang.NullPointerException

if u find out something here is my mail id <deleted>

Expand|Select|Wrap|Line Numbers
  1. package login;
  2.  
  3. import java.awt.EventQueue;
  4. import java.swing.*;
  5. import javax.swing.*;
  6. import java.awt.BorderLayout;
  7. import java.awt.GridBagLayout;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.ActionEvent;
  10. import java.sql.*;
  11.  
  12. public class Remake extends JFrame {
  13.  
  14.  
  15.  
  16.  
  17.     private JFrame frame;
  18.     private JTextField txtfname;
  19.     private JTextField txtadd;
  20.     private JTextField txtemail;
  21.     private JTextField txtuser;
  22.     private JTextField txtlname;
  23.     private JPasswordField txtpass;
  24.     private JTextField txtphone;
  25.     private JComboBox cmbgender;
  26.  
  27.     /**
  28.      * Launch the application.
  29.      */
  30.     public static void main(String[] args) {
  31.         EventQueue.invokeLater(new Runnable() {
  32.             public void run() {
  33.                 try {
  34.                     Remake window = new Remake();
  35.                     window.frame.setVisible(true);
  36.                 } catch (Exception e) {
  37.                     e.printStackTrace();
  38.                 }
  39.             }
  40.         });
  41.     }
  42.  
  43.     /**
  44.      * Create the application.
  45.      */
  46.     public Remake() {
  47.         initialize();
  48.     }
  49.  
  50.     /**
  51.      * Initialize the contents of the frame.
  52.      */
  53.     private void initialize() {
  54.         frame = new JFrame();
  55.         frame.setBounds(100, 100, 743, 460);
  56.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57.         frame.getContentPane().setLayout(null);
  58.  
  59.         JLabel lblNewLabel = new JLabel("pd");
  60.         lblNewLabel.setBounds(226, 34, 258, 54);
  61.         frame.getContentPane().add(lblNewLabel);
  62.  
  63.         JLabel lblNewLabel_1 = new JLabel("First name");
  64.         lblNewLabel_1.setBounds(76, 112, 46, 14);
  65.         frame.getContentPane().add(lblNewLabel_1);
  66.  
  67.         JLabel lblNewLabel_2 = new JLabel("addr");
  68.         lblNewLabel_2.setBounds(76, 162, 46, 14);
  69.         frame.getContentPane().add(lblNewLabel_2);
  70.  
  71.         JLabel lblNewLabel_3 = new JLabel("email");
  72.         lblNewLabel_3.setBounds(76, 222, 46, 14);
  73.         frame.getContentPane().add(lblNewLabel_3);
  74.  
  75.         JLabel lblNewLabel_4 = new JLabel("username");
  76.         lblNewLabel_4.setBounds(76, 278, 46, 14);
  77.         frame.getContentPane().add(lblNewLabel_4);
  78.  
  79.         JLabel lblNewLabel_5 = new JLabel("last name");
  80.         lblNewLabel_5.setBounds(448, 112, 46, 14);
  81.         frame.getContentPane().add(lblNewLabel_5);
  82.  
  83.         JLabel lblNewLabel_6 = new JLabel("gender");
  84.         lblNewLabel_6.setBounds(448, 162, 46, 14);
  85.         frame.getContentPane().add(lblNewLabel_6);
  86.  
  87.         JLabel lblNewLabel_7 = new JLabel("phone");
  88.         lblNewLabel_7.setBounds(448, 222, 46, 14);
  89.         frame.getContentPane().add(lblNewLabel_7);
  90.  
  91.         JLabel lblNewLabel_8 = new JLabel("passwrd");
  92.         lblNewLabel_8.setBounds(448, 278, 46, 14);
  93.         frame.getContentPane().add(lblNewLabel_8);
  94.  
  95.         JButton btnNewButton = new JButton("New button");
  96.         btnNewButton.addActionListener(new ActionListener() {
  97.             public void actionPerformed(ActionEvent e) {
  98.  
  99.                 try {
  100.  
  101.                     String query="INSERT INTO `redu`(`fname`, `lname`, `addr`, `gender`, `email`, `phone`, `username`, `password`) VALUES (?,?,?,?,?,?,?,?)";
  102.                     Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/remake","root","");
  103.                     PreparedStatement pst=con.prepareStatement(query);
  104.  
  105.                     pst.setString(1, txtfname.getText());
  106.                     pst.setString(2, txtlname.getText());
  107.                     pst.setString(3, txtadd.getText());
  108.                     pst.setString(4, cmbgender.getSelectedItem().toString());
  109.                     pst.setString(5, txtemail.getText());
  110.                     pst.setString(6, txtphone.getText());
  111.                     pst.setString(7, txtuser.getText());
  112.                     pst.setString(8, txtpass.getText());
  113.                     pst.executeUpdate();
  114.  
  115.                     JOptionPane.showMessageDialog(null, "register successfully");
  116.                 }
  117.                 catch(Exception ex){
  118.                     System.out.println(ex);
  119.                 }
  120.  
  121.  
  122.  
  123.  
  124.             }
  125.         });
  126.         btnNewButton.setBounds(326, 338, 89, 23);
  127.         frame.getContentPane().add(btnNewButton);
  128.  
  129.         txtfname = new JTextField();
  130.         txtfname.setBounds(208, 109, 86, 20);
  131.         frame.getContentPane().add(txtfname);
  132.         txtfname.setColumns(10);
  133.  
  134.         txtadd = new JTextField();
  135.         txtadd.setBounds(208, 159, 86, 20);
  136.         frame.getContentPane().add(txtadd);
  137.         txtadd.setColumns(10);
  138.  
  139.         txtemail = new JTextField();
  140.         txtemail.setBounds(208, 219, 86, 20);
  141.         frame.getContentPane().add(txtemail);
  142.         txtemail.setColumns(10);
  143.  
  144.         txtuser = new JTextField();
  145.         txtuser.setBounds(208, 275, 86, 20);
  146.         frame.getContentPane().add(txtuser);
  147.         txtuser.setColumns(10);
  148.  
  149.         txtlname = new JTextField();
  150.         txtlname.setBounds(564, 109, 86, 20);
  151.         frame.getContentPane().add(txtlname);
  152.         txtlname.setColumns(10);
  153.  
  154.         txtpass = new JPasswordField();
  155.         txtpass.setBounds(564, 275, 86, 20);
  156.         frame.getContentPane().add(txtpass);
  157.  
  158.         txtphone = new JTextField();
  159.         txtphone.setBounds(564, 219, 86, 20);
  160.         frame.getContentPane().add(txtphone);
  161.         txtphone.setColumns(10);
  162.  
  163.         JComboBox cmbgender = new JComboBox();
  164.         cmbgender.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3"}));
  165.         cmbgender.setBounds(564, 158, 86, 22);
  166.         frame.getContentPane().add(cmbgender);
  167.     }
  168.  
  169. }
May 13 '21 #1
1 2950
Banfa
9,065 Expert Mod 8TB
If you are getting a java.lang.NullPointerException then you should be getting an entire stack trace giving you near enough the line of code that is going wrong. Please post that stack trace.
May 18 '21 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
sammyboy78
by: sammyboy78 | last post by:
Hello again, This time I'm creating a program that creates an array of CD objects and then displays the information. I've created a CD class, a CDInventory class and then a CDInventoryDisplay to...
0
by: gezkk | last post by:
hi, i m using http proxy service to get proxy and host to applet, its working fine with jdk1.5 but getting java.lang.NullPointerException in jdk1.6 And the following is mseeage contains java...
18
by: pradeep84 | last post by:
hi all, i'm using the following code and i'm getting exception in thread "main" java.lang.nullpointerexception at the line which is in bold. help me to solve this problem import...
1
by: ksrashmi | last post by:
HI I am getting following exception when i use mxml tags in jsp <%@ taglib uri="FlexTagLib" prefix="mm" %> can any one tell why i am getting this exception type Exception report message...
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
3
by: makweatan | last post by:
Hello guys... Data is not updated into table. I got this error : java.lang.NullPointerException 00000030 SystemErr R java.lang.NullPointerException 00000030 SystemErr R at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.