Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Scanner error Date: Mon, 11 Jul 2016 15:26:15 -0400 Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <87b76adc-9800-410f-ac5a-3cd25588bb3a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 11 Jul 2016 19:26:18 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e905b254ff7ab0d0dda2c4195925adb8"; logging-data="8534"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/k6oeNA9xDlC4oX8TvKA4" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Cancel-Lock: sha1:6SGVBP35tkLysIi5n63XB1pohx4= Xref: csiph.com comp.lang.java.programmer:34859 On 7/11/2016 3:23 PM, Stefan Ram wrote: > kalisha malama writes: >> How old are you ?21 >> Do you have a Coupon?(Y/N)Exception in thread "main" java.lang.NullPointerException >> at Apples.main(Apples.java:15) > > The method declaration > > void f( final java.lang.CharSequence s ){ s.charAt( 0 ); } > > assumes that »s« is not null, otherwise there will be an exception, > which is a kind of runtime error. > > The code could be replaced by, for example, > > void f( final java.lang.CharSequence s ){ if( s != null )s.charAt( 0 ); } > > . I, too, sometimes type faster than I think. Will you post a correction? -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM