Java3D Appearance Help

Discussion in 'Java' started by Hoagie, Dec 20, 2003.

  1. Hoagie

    Hoagie Guest

    Hello all.

    I am trying to get a Java3D Appearance function to work. I had this
    working in the past, but recently got a new computer and also upgraded
    from JBuilder 8 to JBuilder 9. Now, when I try to run my application
    it crashes with a NullPointException.

    The function is below. The error I get is just under it -- the line
    in question is:
    ImageComponent2D image = loader.getImage();

    As I mentioned, this used to work. I don't know what I didn't
    configure this time around, or perhaps I got a newer version of Java3D
    that requires me to load the image slightly differently?

    I am using JDK 1.4.2_2, with J3D 1.3.1. The image I am attempting to
    load does exist where the program thinks it exists. ;)

    Thank you for any help!!

    - Hoag

    P.S.
    I've heard there is a Java3D newsgroup, but my server doesn't seem to
    have it. Sorry. :(


    private Appearance createAppearance(String filename) {
    Appearance appear = new Appearance();

    BufferedImage buffer = null;
    try {
    buffer = javax.imageio.ImageIO.read(new File(filename));
    } catch (IOException e) {
    System.out.println("Failed to open the BMP");
    }

    TextureLoader loader = new TextureLoader(buffer, "bmp");
    ImageComponent2D image = loader.getImage();

    if(image == null) {
    System.out.println("Load failed for texture: " + filename);
    }

    // can't use parameterless constuctor
    Texture2D texture = new Texture2D(Texture.BASE_LEVEL,
    Texture.RGBA,
    image.getWidth(),
    image.getHeight());
    texture.setImage(0, image);
    texture.setEnable(true);
    texture.setMagFilter(Texture.NICEST);

    appear.setTexture(texture);

    //appear.setTransparencyAttributes(new
    TransparencyAttributes(TransparencyAttributes.FASTEST, 0.1f));

    return appear;
    }

    java.lang.NullPointerException

    at
    javax.media.j3d.ImageComponent2D.<init>(ImageComponent2D.java:167)

    at
    com.sun.j3d.utils.image.TextureLoader.getImage(TextureLoader.java:523)

    at
    org.rightstep.j3d.loaders.gnd.GNDLoader.createAppearance(GNDLoader.java:247)

    at
    org.rightstep.j3d.loaders.gnd.GNDLoader.load(GNDLoader.java:87)

    at
    org.rightstep.j3d.loaders.gnd.GNDLoader.load(GNDLoader.java:49)

    at org.rightstep.javaro.JavaRO.guiInit(JavaRO.java:87)

    at org.rightstep.javaro.JavaRO.<init>(JavaRO.java:48)

    at
    org.rightstep.javaro.Application.<init>(Application.java:20)

    at org.rightstep.javaro.Application.main(Application.java:51)
     
    Hoagie, Dec 20, 2003
    #1
    1. Advertising

  2. Hoagie

    Hoagie Guest

    After a little more foot work, I changed the TextLoader line to the
    following:

    TextureLoader loader = new TextureLoader(filename, "bmp", null);

    Now I get an error that the BMP file failed to load. The BMP is
    there, it's a valid image file. What could be causing this problem?

    Thanks again!

    On Sat, 20 Dec 2003 04:11:34 GMT, Hoagie <> wrote:

    >Hello all.
    >
    >I am trying to get a Java3D Appearance function to work. I had this
    >working in the past, but recently got a new computer and also upgraded
    >from JBuilder 8 to JBuilder 9. Now, when I try to run my application
    >it crashes with a NullPointException.
    >
    >The function is below. The error I get is just under it -- the line
    >in question is:
    > ImageComponent2D image = loader.getImage();
    >
    >As I mentioned, this used to work. I don't know what I didn't
    >configure this time around, or perhaps I got a newer version of Java3D
    >that requires me to load the image slightly differently?
    >
    >I am using JDK 1.4.2_2, with J3D 1.3.1. The image I am attempting to
    >load does exist where the program thinks it exists. ;)
    >
    >Thank you for any help!!
    >
    >- Hoag
    >
    >P.S.
    >I've heard there is a Java3D newsgroup, but my server doesn't seem to
    >have it. Sorry. :(
    >
    >
    > private Appearance createAppearance(String filename) {
    > Appearance appear = new Appearance();
    >
    > BufferedImage buffer = null;
    > try {
    > buffer = javax.imageio.ImageIO.read(new File(filename));
    > } catch (IOException e) {
    > System.out.println("Failed to open the BMP");
    > }
    >
    > TextureLoader loader = new TextureLoader(buffer, "bmp");
    > ImageComponent2D image = loader.getImage();
    >
    > if(image == null) {
    > System.out.println("Load failed for texture: " + filename);
    > }
    >
    > // can't use parameterless constuctor
    > Texture2D texture = new Texture2D(Texture.BASE_LEVEL,
    >Texture.RGBA,
    > image.getWidth(),
    >image.getHeight());
    > texture.setImage(0, image);
    > texture.setEnable(true);
    > texture.setMagFilter(Texture.NICEST);
    >
    > appear.setTexture(texture);
    >
    > //appear.setTransparencyAttributes(new
    >TransparencyAttributes(TransparencyAttributes.FASTEST, 0.1f));
    >
    > return appear;
    > }
    >
    >java.lang.NullPointerException
    >
    > at
    >javax.media.j3d.ImageComponent2D.<init>(ImageComponent2D.java:167)
    >
    > at
    >com.sun.j3d.utils.image.TextureLoader.getImage(TextureLoader.java:523)
    >
    > at
    >org.rightstep.j3d.loaders.gnd.GNDLoader.createAppearance(GNDLoader.java:247)
    >
    > at
    >org.rightstep.j3d.loaders.gnd.GNDLoader.load(GNDLoader.java:87)
    >
    > at
    >org.rightstep.j3d.loaders.gnd.GNDLoader.load(GNDLoader.java:49)
    >
    > at org.rightstep.javaro.JavaRO.guiInit(JavaRO.java:87)
    >
    > at org.rightstep.javaro.JavaRO.<init>(JavaRO.java:48)
    >
    > at
    >org.rightstep.javaro.Application.<init>(Application.java:20)
    >
    > at org.rightstep.javaro.Application.main(Application.java:51)
     
    Hoagie, Dec 20, 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. P. Flavin
    Replies:
    0
    Views:
    6,400
    P. Flavin
    Oct 17, 2003
  2. Sheena
    Replies:
    1
    Views:
    397
    Harald Hein
    Oct 28, 2003
  3. x2

    Need Java3D help

    x2, Nov 28, 2003, in forum: Java
    Replies:
    1
    Views:
    395
    Andrew Thompson
    Nov 28, 2003
  4. Angus Parvis

    Java3D: changing appearance of a Box

    Angus Parvis, Jun 22, 2005, in forum: Java
    Replies:
    0
    Views:
    4,047
    Angus Parvis
    Jun 22, 2005
  5. Angelo
    Replies:
    1
    Views:
    313
    Angelo
    May 10, 2007
Loading...

Share This Page