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)
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!