🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17224

Re: Throws

#17224
From: William Yu
Date: Thu, 03 Dec 1998 00:00
33 lines
1628 bytes
Shahid Juma wrote:

>   public Object pop() throws EmptyStackException {
>   holdings = tempo.data;
>        if (top.get_next() == null) {     <<<--------- PROBLEM HERE
>            top = null;
>            tempo = null;
>            temp = null;
>        throw new EmptyStackException();
>        }
>
>   else {
>            tempo = tempo.get_next();
>            top.set_next(null);
>            top = tempo;
>     }
>        return holdings;
>
>    }
>
>  This doen't seem to work, it says the following:
>
> java.lang.NullPointerException
>         at LinkedStack.pop(Compiled Code)
>         at LinkedStack.pop(Compiled Code)
>         at Assignment4.interactiveTest(Compiled Code)
>         at Assignment4.main(Assignment4.java:31)
>
> Is anything wrong anywhere?

If your stack is empty, then TOP = NULL.  However, your code never checks
whether TOP is NULL or not -- instead, it immediately looks at TOP.GET_NEXT()
which will always cause a NullPointerException if the stack is empty.
Technical Details
Message-ID: <36677743.3E8D40B1@Bigfoot.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3666FA68.1AE15DBC@interlog.com> <3732fbbd.825410610@90.0.0.40> <366732FB.D0235A7F@interlog.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,32517523289d282
X-Google-Attributes: gidf74b3,public
From: William Yu <William_Yu@Bigfoot.com>
Subject: Re: Throws
Date: 1998/12/03
Message-ID: <36677743.3E8D40B1@Bigfoot.com>
X-Deja-AN: 418511464
Content-Transfer-Encoding: 7bit
References: <3666FA68.1AE15DBC@interlog.com> <3732fbbd.825410610@90.0.0.40> <366732FB.D0235A7F@interlog.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language