Results 1 to 4 of 4
  1. #1
    sanu is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Question NullPointerException

    Hi I am just a beginner in java..
    i am facing the problem of "NullPointerException" ..i exactly can't understand as to why it comes...pls help me out guys....
    i have pasted the code below:-

    Java Code:
     private void loginbtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try{
                String s = "";
                String log = logtf.getText();
                for(int i = 0;i<log.length();i++){
                    char ch = log.charAt(i);
                    if(Character.isDigit(ch)==false)
                          op.showMessageDialog(null,"Please enter your CUSTOMER NUMBER given at the time of Registration");
                }
                if(log.equals("")){
                      op.showMessageDialog(null, "Please enter your Login ID number");
                      logtf.requestFocus();
                }
                String query3 = "select custname,custid,sex from customer where custid="+log+";";
                System.out.println(query3);
                ResultSet rs = stmt.executeQuery(query3);
                if(rs.next()){
                    String custno = rs.getString("custid");
                    String cname = rs.getString("custname");
                    String sex = rs.getString("sex");
                    if(sex.equalsIgnoreCase("Male"))
                        s = "Mr.";
                    else
                        s = "Mrs.";
                    if(custno.equals(log))
                        op.showMessageDialog(null, "Enter Granted "+s+" "+cname);
                    msgtype.setVisible(true);
                }
                else
                   op.showMessageDialog(null, "Such an ID does not exist please Register inorder to logon");
            }
            catch(Exception e){
                op.showMessageDialog(null,e);
    
            }
    Pls provide me a solution for this..:(
    Last edited by Fubarable; 08-21-2010 at 08:43 PM. Reason: Moderator Edit: Code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello, and welcome to the forum.

    It would help immensely if you could tell us which line throws this exception.


    Also, I hope you don't mind that I edited your code and added code tags which should help make your posted code retain its formatting and be more readable.

    To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    Best of luck, and again, welcome!

  3. #3
    sanu is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default

    thanks for the editing as i am new to this i dint noe abt it...
    actually i can jst see a warning in the places where 'op.show........' is used it tells "Accessing a static method"..there are no errors in the code but when i execute it it tells java.lang.NullPointerException...Is there anything which i shud change in the code?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sanu View Post
    actually i can jst see a warning in the places where 'op.show........' is used it tells "Accessing a static method"..there are no errors in the code but when i execute it it tells java.lang.NullPointerException...
    Again, you need to tell us more. The NullPointerException message produced by the JVM gives you a lot more information than you're telling us, including the line which is throwing this exception. Unless you tell us this, it will be very hard to help us. You will need to use the line number given to you to find out which line is causing the exception and then show us the line itself, not the number (which won't mean much to us).

    Is there anything which i shud change in the code?
    One more request, please avoid unnecessary non-standard abbreviations such as "shud", "jst", etc...

    Many of us volunteers don't speak English as a primary language and to help us more easily help you, we all appreciate it greatly if you take the effort to fully write out your words.

    Much luck!

Similar Threads

  1. NullPointerException
    By GPB in forum New To Java
    Replies: 8
    Last Post: 02-21-2010, 04:05 PM
  2. NullPointerException
    By Juuno in forum New To Java
    Replies: 1
    Last Post: 02-11-2010, 06:43 PM
  3. NullPointerException help me!
    By phancuong87 in forum New To Java
    Replies: 4
    Last Post: 01-19-2010, 05:01 PM
  4. NullPointerException
    By mjz in forum JDBC
    Replies: 1
    Last Post: 08-06-2009, 12:46 PM
  5. NullPointerException
    By adeeb in forum AWT / Swing
    Replies: 3
    Last Post: 06-11-2008, 09:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •