I can think of two reasons why there would be a difference between an applet and an application in your case.
 
First, applets do not have access to files on the hard disk unless you specifically specify that permission. If you run it in appletviewer, it might give you file access without specifying. Second, if the applet is run from the browser, the working directory or . could be different from what you expect. I would try a file input stream on the "./computer.jpg" and see if you can better see what the problem is.
----- Original Message -----
Sent: Sunday, July 15, 2001 8:01 PM
Subject: [JAVA3D] works as an application but not as an applet for ImageComponent2D

Hi Java3D:

I can get my program to run as an application.  But, when I try to run it as an

applet I get a null pointer exception in my ImageComponent2D.

I am a newbie so I do not know where I am going wrong.

What is it that I do not know?

Can I get a clue?

Michael Carter, student

----------------------- see below -----------------------

This methods gives a NullPointerException

  at Javax.media.j3d.ImageComponent2D<init>(ImageComponent2D.java:166)
 
 
 

   void getTextures()
   {
      System.out.println("attempt to load texture from file: " + "sky.jpg" );
      tex = new TextureLoader("sky.jpg", new String("RGB"), this);
      textureAppear = new Appearance[5] ;
      String[] filename = new String[6] ;
      filename[0] = new String("file:./computer.jpg") ;
      filename[1] = new String("file:./circuit.jpg") ;
      filename[2] = new String("file:./wall.jpg") ;
      filename[3] = new String("file:./wall2.jpg") ;
      filename[4] = new String("file:./ground.jpg") ;
      for( int i = 0; i < 5; i++)
      {
         System.out.println("attempt to load texture from file: "+filename[i]);
         TextureLoader loader = null ;
            try
            {
               loader = new TextureLoader( new URL( filename[i] ), this);
            }
            catch (java.net.MalformedURLException e)
            {
               System.out.println( e.getMessage() ) ;
               System.exit(1) ;
            }
         ImageComponent2D image = loader.getImage() ;
         Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB,
                                         image.getWidth(), image.getHeight()) ;

         if(image == null)
            System.out.println("load failed for texture: "+filename[i]) ;
            texture.setImage(0, image);
            texture.setEnable(true);
            texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
            texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);
            textureAppear[i] = new Appearance() ;
            textureAppear[i].setTexture(texture) ;
      }
   }

 

Reply via email to