null pointer exeption : how solve it ?
Code:
String[] lines = new String[10];
String s ;
program stop at here
Code:
if (lines[i].isEmpty() == false){
and sometimes at
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
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";
Re: null pointer exeption : how solve it ?
Quote:
Originally Posted by
Norm
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
Re: null pointer exeption : how solve it ?
norm you are exaillent . i never see in any forum so rapidly one persin answer
thank you
Re: null pointer exeption : how solve it ?
Quote:
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.
1 Attachment(s)
Re: null pointer exeption : how solve it ?
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
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.
Re: null pointer exeption : how solve it ?
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)
Re: null pointer exeption : how solve it ?
Quote:
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.
Re: null pointer exeption : how solve it ?
Quote:
Originally Posted by
Norm
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){
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.
Re: null pointer exeption : how solve it ?
Quote:
Originally Posted by
Norm
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?