Hi,
I have a problem needed to solved.
Now I want to change the texture of a object, such as a Box.
First  use class TextureLoader and getTexture()  to get the Texture of  texture0 and 
texture1,as following:

TextureLoader   texLoader=new TextureLoader("MyTextures\\flooring.jpg",this);
TextureLoader   texLoader1=new TextureLoader("MyTextures\\floor-planks.jpg",this);
Texture    texture=texLoader.getTexture();
Texture    texture1=texLoader1.getTexture();

use  as following code to set Texture of Appearance:

Appearance  app=new Appearance();
PolygonAttributes pa=new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    app.setCapability(app.ALLOW_TEXTURE_READ|app.ALLOW_TEXTURE_WRITE);
    app.setPolygonAttributes(pa);
    app.setTexture(texture0);
 box=new Box(.2f,.15f,.15f,Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,app);
...

then according to the event to change the texture of Box,the code is:

public void actionPerformed(ActionEvent e){
    if(e.getSource()==bt1){   // bt1 is a button 
      app.setTexture(texture);
    }
    if(e.getSource()==bt2){  //bt2 is a button
      app.setTexture(texture1);
    }
  }

but when I click the bt1 and bt2 give the messeage of error:
Exception occurred during event dispatching:

java.lang.NullPointerException

 at java3d.Actionlisten.actionPerformed(Actionlisten.java:132)

 at java.awt.Button.processActionEvent(Button.java:329)

 at java.awt.Button.processEvent(Button.java:302)

 at java.awt.Component.dispatchEventImpl(Component.java:2595)

 at java.awt.Component.dispatchEvent(Component.java:2499)

 at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)

 at 
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:134)

 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:101)

 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)

 at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)

Exception occurred during event dispatching:

java.lang.NullPointerException

 at java3d.Actionlisten.actionPerformed(Actionlisten.java:143)

 at java.awt.Button.processActionEvent(Button.java:329)

 at java.awt.Button.processEvent(Button.java:302)

 at java.awt.Component.dispatchEventImpl(Component.java:2595)

 at java.awt.Component.dispatchEvent(Component.java:2499)

 at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)

 at 
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:134)

 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:101)

 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)

 at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)

could yop tell me how to solve the question?
Thanks in advance.
Wu Fangsheng



칻&ޱzf%lzjw(݊w%ע^nrazg('P7
SLZ+ޭazZlzw^bڽ.&jwbnu觶ܨ~^,jzZ


Reply via email to