| | |
getting nullpoint exception again
![]() |
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
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 friends so i just took a chance if u could solve it.But its ok. sorry again . thanks akulkarni
•
•
Join Date: Apr 2008
Posts: 964
Reputation:
Solved Threads: 143
OK. But you already have the explanation of this NPE, and just patching the code to bypass it still won't make your program work.
If you really don't want to use split, you should have program that looks like this:
create empty string array for words.
start copying input to a temporary string until you hit a " "
put the temp string into the first/next element of word array
repeat until input exhausted.
Test, and don't try to do anything else until this works.
Create temp String "" to hold longest.
Compare length of each word against length of the temp String
if it's longer, copy word to the temp String
When all words processed, temp String contains the longest one.
If you really don't want to use split, you should have program that looks like this:
create empty string array for words.
start copying input to a temporary string until you hit a " "
put the temp string into the first/next element of word array
repeat until input exhausted.
Test, and don't try to do anything else until this works.
Create temp String "" to hold longest.
Compare length of each word against length of the temp String
if it's longer, copy word to the temp String
When all words processed, temp String contains the longest one.
Last edited by JamesCherrill; Jul 5th, 2009 at 2:17 pm.
![]() |
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 |
addball android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows





