| | |
getting nullpoint exception again
![]() |
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
not clear with the basics of nullpont error; trying to create student database import java.io.*; class student1 { String name; int id; public void getdata(String name1,int id1) { name=name1; id=id1; } public void putdata() { System.out.println("\t"+id+" "+name); } } class student { public static void main(String args[])throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); BufferedReader br1= new BufferedReader(new InputStreamReader(System.in)); student1[] n=new student1[10]; for(int i=0;i<5;i++) { n[i].getdata(br.readLine(),Integer.parseInt(br1.readLine())); n[i].putdata(); } } }
The exception contains a line number, so which line is it?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
java:29 line 29 thanks
And which line there is line 29?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
n[i].getdata(....) tried without using BufferedReader directly putting values but same error.Object seems to be null.
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
thanks a lot a bunch it worked
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
Dear James i wished you could solve this NPE too. i am trying to separate the words and print the longest. i tried using s.length but found difficult getting error at toCompare which compares the length of strings class maxstring1 { public static void main(String args[]) { String s1="nikhil is a good boy"; int d;int x=0; d=s1.length(); String[] s2=new String[20]; char ch; for(int i=0;i<=d-1;i++) { ch=s1.charAt(i); if(ch==' ') { s2[i]=new String(); s2[i]=s1.substring(x,i-1); x=i+1; } } for(int i=0;i<=d-1;i++) { s2[i]=new String(); System.out.println(s2[i]); if(s2[i].compareTo(max)>0) max=s2[i]; } System.out.println(max); } }
•
•
Join Date: Apr 2008
Posts: 965
Reputation:
Solved Threads: 144
NPE is probably because max isn't defined or initialised. But you have other problems.eg: S2 is initialised to empty Strings, but you never put anything else in there before comparing them. And you compare them alphabetically, not by length.
Have a look at the split(" ") method for Strings - this will get you your words just like you need them...
EDIT: I just saw that you have already posted this problem, and a number of other posters have given the same advice already, and you don't seem to have followed it. Are you wasting my time?
Have a look at the split(" ") method for Strings - this will get you your words just like you need them...
EDIT: I just saw that you have already posted this problem, and a number of other posters have given the same advice already, and you don't seem to have followed it. Are you wasting my time?
Last edited by JamesCherrill; Jul 5th, 2009 at 1:47 pm.
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
[code]
i am sorry
i wanted to do it in my way. I know and remember other posts.But if you could solve the NPE problem in one case u could do it in other as well. I know the split or String tokenizer method. (i am tryng to explain for loop to one of my friend so i just took a chance if u could solve it.But its ok.
sorry again .
thanks
akulkarni
i am sorry
i wanted to do it in my way. I know and remember other posts.But if you could solve the NPE problem in one case u could do it in other as well. I know the split or String tokenizer method. (i am tryng to explain for loop to one of my friend so i just took a chance if u could solve it.But its ok.
sorry again .
thanks
akulkarni
![]() |
Similar Threads
- purpose of exception handling 'finally' clause (Java)
- help with sort using Calendar class getting null pointer exception (Java)
- fatal exception OE VXD VFAT (Windows 95 / 98 / Me)
- Exception messages reappears constantly! (Windows NT / 2000 / XP)
- Arithmetic Exceptions and exception-handling statements (Java)
Other Threads in the Java Forum
- Previous Thread: open local folder with a jButton
- Next Thread: why doesn't it overwrites the array
| Thread Tools | Search this Thread |
911 actionlistener addball addressbook android api applet application array automation binary block bluetooth button character class client code component consumer css csv database desktop developmenthelp eclipse ee error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia jvm lego linked linux loan mac map method mobile netbeans notdisplaying number objects online oriented phone printf problem program programming project projects recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server service set singleton sms software sort sql swing system test textfields threads time title tree tutorial-sample ubuntu update windows working






