Results 1 to 12 of 12
  1. #1
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default null pointer exeption : how solve it ?

    Java Code:
    String[] lines = new String[10];
    String s ;
    program stop at here
    Java Code:
    if (lines[i].isEmpty() == false){
    and sometimes at
    Java Code:
    if (s.isEmpty()==false){
    with null pointer exeption

    i test s!=null and i test
    "".equles(s)

    but again i get this exeption
    i read lines[i] from file
    Last edited by miki_ir; 09-04-2011 at 09:35 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default Re: null pointer exeption : how solve it ?

    The variables you are using have not been given values. There value is null. The value needs to be an object.
    You need to assign them non null values.
    s = "A String";

    lines[0] = "Another String";

  3. #3
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default Re: null pointer exeption : how solve it ?

    Quote Originally Posted by Norm View Post
    The variables you are using have not been given values. There value is null. The value needs to be an object.
    You need to assign them non null values.
    s = "A String";

    lines[0] = "Another String";
    but i get value from file
    and it good work but at end i get exeption
    i cant manually set value of theme thay get value from file
    Last edited by miki_ir; 09-04-2011 at 09:45 PM.

  4. #4
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default Re: null pointer exeption : how solve it ?

    norm you are exaillent . i never see in any forum so rapidly one persin answer
    thank you

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default Re: null pointer exeption : how solve it ?

    but at end i get exeption
    You must have missed giving a variable a good value.
    When you get an exception, please copy and paste here the full text of the error message.

  6. #6
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default Re: null pointer exeption : how solve it ?

    Java Code:
    	if (t1.getText().equals("") ){        		
            				  JOptionPane.showMessageDialog(null ,"etelat ra por konid");
          				}
          				else{
          					lines = mof.getString("book.txt",t1.getText())	;
          		  			 if (lines.equals("")){        		
            					 JOptionPane.showMessageDialog(null ,"In Ketab Vojod Nadarad .");	  
          					}
          					else{
          						sb1.append("\nList Of Book in Library With Like This Name Is: \n");   System.out.println(sb1.toString());
          						sb2.append("\nBut This  Book Are In Amanat: \n");System.out.println(sb2.toString());
          						for(int i = 0 ; i<lines.length;i++){	
          						System.out.println("\n000\n");
           							if (lines[i].isEmpty() == false){
           								System.out.println(lines[i]+"---------");
            							String[] values = lines[i].split(",");  
            							s  = values[0]; 
            							System.out.println(s+"++++++");
            							sb1.append("\n"+lines[i]+"\n");	
            							
            							s = mof.findLine("amanat.txt", s);
            							System.out.println(s+"+++***+++");
            							System.out.println(s);
            						}
            						System.out.println("-////////////-");
            						if (s.isEmpty()==false){	
    								System.out.println(s);
    								sb2.append("\n"+lines[i]+"\n");
    
            						}
    							
          						}
    
          						JOptionPane.showMessageDialog(null ,sb3.append(sb1.toString()).append(sb2.toString()).toString());
    
          					}
    and this is my file content
    1,java2EE,man
    2,java2Ee,You
    12,java,ali,hich
    13,java,ali,hich
    14,java,ali,hich
    Attached Thumbnails Attached Thumbnails null pointer exeption : how solve it ?-untitled.jpg  
    Last edited by miki_ir; 09-05-2011 at 03:13 AM.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default Re: null pointer exeption : how solve it ?

    Sorry, can't read the screen print.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    Are you sure that ALL of the slots in the lines array have good values?
    If some could be null you should test them for being null BEFORE testing if they hold an empty String.
    Last edited by Norm; 09-04-2011 at 10:00 PM.

  8. #8
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default Re: null pointer exeption : how solve it ?

    Java Code:
    List Of Book in Library With Like This Name Is:
    
    
    But This  Book Are In Amanat:
    
    
    000
    
    1,java2EE,man---------
    1++++++
    12,12,1390,1390+++***+++
    12,12,1390,1390
    -////////////-
    12,12,1390,1390
    
    000
    
    2,java2Ee,You---------
    2++++++
    12,12,1390,1390+++***+++
    12,12,1390,1390
    -////////////-
    12,12,1390,1390
    
    000
    
    12,java,ali,hich---------
    12++++++
    12,12,1390,1390+++***+++
    12,12,1390,1390
    -////////////-
    12,12,1390,1390
    
    000
    
    13,java,ali,hich---------
    13++++++
    12,12,1390,1390+++***+++
    12,12,1390,1390
    -////////////-
    12,12,1390,1390
    
    000
    
    14,java,ali,hich---------
    14++++++
    +++***+++
    
    -////////////-
    
    000
    
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at SearchForm.okButtonEvent(SearchForm.java:94)
            at SearchForm$1.actionPerformed(SearchForm.java:50)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
    95)
    Last edited by miki_ir; 09-05-2011 at 03:12 AM.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default Re: null pointer exeption : how solve it ?

    xception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at SearchForm.okButtonEvent(SearchForm.java:94)
    There is a variable at line 94 that has a value of null when you try to use it to reference a method.
    Look at that line and see what variable is null and then back track in your code to see why the variable does not have a good value.

    Are you sure that ALL of the slots in the lines array have good values?
    If some could be null you should test them for being null BEFORE testing if they hold an empty String.

  10. #10
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default Re: null pointer exeption : how solve it ?

    Quote Originally Posted by Norm View Post
    If some could be null you should test them for being null BEFORE testing if they hold an empty String.
    maybee when read from file some value be null
    i use
    if (lines[i].isEmpty() == false) anf test lines[i].equals("null") but i get exeption
    how i check?
    how i should to do?
    line 94 is : if (lines[i].isEmpty() == false){
    Last edited by miki_ir; 09-05-2011 at 02:24 AM.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default Re: null pointer exeption : how solve it ?

    You test if a variable is null by using the == operator: if(lines[x] == null ...
    The equals method is for comparing the contents of two objects.
    Last edited by Norm; 09-05-2011 at 02:45 AM.

  12. #12
    miki_ir is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Rep Power
    0

    Default Re: null pointer exeption : how solve it ?

    Quote Originally Posted by Norm View Post
    You test if a variable is null by using the == operator: if(lines[x] == null ...
    The equals method if for comparing the contents of two objects.
    thanke youuuuuuuuuuuuu
    god help you

    it work
    this was problem
    this one day i search and work to solve it.
    how i avoid this problem that waste my time norm how learn like you?

Similar Threads

  1. how to solve debug this null pointer
    By aborgeld in forum Advanced Java
    Replies: 5
    Last Post: 05-13-2011, 11:48 AM
  2. Null Pointer Exeption
    By Aldane in forum AWT / Swing
    Replies: 3
    Last Post: 03-19-2011, 10:11 AM
  3. Null Pointer
    By theen3my in forum AWT / Swing
    Replies: 3
    Last Post: 10-03-2009, 02:10 PM
  4. null pointer help
    By mayhewj7 in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 11:51 PM
  5. null pointer exeption
    By mj23brm in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 11:50 PM

Posting Permissions

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