Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #906
| From | lewbloch <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Help needed. |
| Date | 2011-07-28 08:50 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <f9f7c570-4d0b-4ab7-91a5-b1e839735fab@f39g2000prb.googlegroups.com> (permalink) |
| References | <37f0537b-a064-4b12-9b6f-c104df52f4ba@k15g2000yqd.googlegroups.com> <j0nl7o$tpu$1@dont-email.me> <07461a44-6c77-4ecc-aa5b-84d8450d8f86@m18g2000vbl.googlegroups.com> |
neil furnival wrote:
> markspace wrote:
>> neil furnival wrote:
>
>>> Exception in thread "main" java.lang.NullPointerException
>>> reply = myScanner.findInLine(".").charAt(0);
>
>> You should learn how to debug your own programs, it's an important part
>> of programming.
>>
>> My guess is in the line above the pattern "." was not found and
>> findInlIne() returned null:
>>
>> "If no such pattern is detected in the input up to the next line
>> separator, then null is returned"
>>
>> <http://download.oracle.com/javase/6/docs/api/java/util/Scanner.html#f...>
>>
>> I'll let you discover how to verify that this is indeed the problem, and
>> what to do about it.
>
> sorted. replaced
What did you sort?
> reply = myScanner.next().charAt(0);
>
> in place of
>
> reply = myScanner.nextInLine(".").charAt(0);
>
> And works thanks for your reply.
"works" is such a strong word. The call to 'Scanner#next()' can fail
in interesting ways that could break your code.
Check the Javadocs for details.
(Note that 'Scanner#nextInLine()' takes a pattern, not a literal
string, as its argument.)
--
Lew
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Help needed. neil furnival <neil.furnival@googlemail.com> - 2011-07-26 15:47 -0700
Re: Help needed. markspace <-@.> - 2011-07-26 17:13 -0700
Re: Help needed. neil furnival <neil.furnival@googlemail.com> - 2011-07-27 01:49 -0700
Re: Help needed. lewbloch <lewbloch@gmail.com> - 2011-07-28 08:50 -0700
Re: Help needed. lewbloch <lewbloch@gmail.com> - 2011-07-30 16:19 -0700
Re: Help needed. Gene Wirchenko <genew@ocis.net> - 2011-07-27 11:33 -0700
Re: Help needed. Roedy Green <see_website@mindprod.com.invalid> - 2011-07-26 22:09 -0700
csiph-web