| | |
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: 971
Reputation:
Solved Threads: 146
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 |
actuate add android api applet application applications array arrays automation balls bank binary bluetooth business chat class clear client code codesnippet collections component database defaultmethod development dice digit dragging ebook eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health hql html hyper ide idea image infinite int integer invokingapacheantprogrammatically j2me java javame javaprojects jni jpanel julia linux list main map method methods mobile myregfun mysql netbeans nonstatic openjavafx parameter pearl php problem program project recursion repositories scanner scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string sun superclass swing swt thread threads tree windows





