943,876 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 596
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 5th, 2009
0

Re: getting nullpoint exception again

Java Syntax (Toggle Plain Text)
  1.  
  2. i am sorry
  3.  
  4. 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.
  5. sorry again .
  6.  
  7. thanks
  8. akulkarni
Reputation Points: 11
Solved Threads: 4
Junior Poster
akulkarni is offline Offline
111 posts
since Jun 2009
Jul 5th, 2009
0

Re: getting nullpoint exception again

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.
Last edited by JamesCherrill; Jul 5th, 2009 at 2:17 pm.
Featured Poster
Reputation Points: 1924
Solved Threads: 951
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JComponent Placement
Next Thread in Java Forum Timeline: why doesn't it overwrites the array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC