null pointer exceptions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tennessee James Leeuwenburg

    null pointer exceptions

    It seems to be the case that there are some null pointer exceptions which
    Java can handle, but Jython can't. Which doesn't make sense to me, as with
    Jython, it is Java which is doing the work.

    Are there any good guides to this?

    I have a class which includes adding an ImageIcon. If the required graphic
    resource isn't present, there is a NullPointerExce ption. Java doesn't care
    - the straight Java program handles it internally and gets on with life.
    But when I include it from Python, it explodes.

    It may be because the resource is specified using a relative pathname.
    When Jython executes, it may be not using the current directory as its'
    base for relative paths, but could be using JYTHON_HOME, which could lead
    to this behaviour.

    Can anyone tell me what Jython uses for its' relative path base?
    Can anyone describe how Jython handles exceptions that is different from
    Java?

    Thanks,
    -Tennessee
  • Erik Max Francis

    #2
    Re: null pointer exceptions

    Tennessee James Leeuwenburg wrote:
    [color=blue]
    > I have a class which includes adding an ImageIcon. If the required
    > graphic
    > resource isn't present, there is a NullPointerExce ption. Java doesn't
    > care
    > - the straight Java program handles it internally and gets on with
    > life.
    > But when I include it from Python, it explodes.[/color]

    A java.lang.NullP ointerException is just an exception like anything
    else. Can't you just catch it?

    max@oxygen:~/tmp% cat NullCaster.java
    import java.lang.*;

    public class NullCaster
    {
    public static void main(String[] args)
    {
    Object nullObject = null;
    String nullString = (String) nullObject;
    nullString.leng th();
    }
    }
    max@oxygen:~/tmp% javac NullCaster.java
    max@oxygen:~/tmp% jython
    Jython 2.1 on java1.4.1 (JIT: null)
    Type "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
    >>> import java.lang
    >>> import NullCaster
    >>> try:[/color][/color][/color]
    .... NullCaster.main ([])
    .... except java.lang.NullP ointerException , e:
    .... print 'oops:', e
    ....
    oops: java.lang.NullP ointerException

    --
    Erik Max Francis && [email protected] && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ Wretches hang that jurymen may dine.
    \__/ Alexander Pope

    Comment

    Working...