null pointer exceptions

Discussion in 'Python' started by Tennessee James Leeuwenburg, Jul 18, 2003.

  1. 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 NullPointerException. 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
    Tennessee James Leeuwenburg, Jul 18, 2003
    #1
    1. Advertising

  2. Tennessee James Leeuwenburg wrote:

    > I have a class which includes adding an ImageIcon. If the required
    > graphic
    > resource isn't present, there is a NullPointerException. 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.


    A java.lang.NullPointerException 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.length();
    }
    }
    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.
    >>> import java.lang
    >>> import NullCaster
    >>> try:

    .... NullCaster.main([])
    .... except java.lang.NullPointerException, e:
    .... print 'oops:', e
    ....
    oops: java.lang.NullPointerException

    --
    Erik Max Francis && && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ Wretches hang that jurymen may dine.
    \__/ Alexander Pope
    Erik Max Francis, Jul 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,479
    Mike Schilling
    Mar 29, 2006
  2. aa
    Replies:
    4
    Views:
    342
    Patricia Shanahan
    Jul 24, 2006
  3. Alan

    Null pointer exceptions

    Alan, Dec 25, 2007, in forum: Java
    Replies:
    4
    Views:
    543
    Roedy Green
    Dec 28, 2007
  4. aneuryzma
    Replies:
    3
    Views:
    690
    Jim Langston
    Jun 16, 2008
  5. Christopher
    Replies:
    4
    Views:
    425
    Ruben Safir
    Jul 9, 2011
Loading...

Share This Page