# Applet not running in a Browser !



## Guest (1. Mrz 2005)

Hi,

I have made an applet and when it runs in a browser or with appletviewer it gives the following error :- 

"The security manager has denied loading of native libraries. Only trusted classes and signed JAR files can access native libraries". 


The code for the applet is :- 


```
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.BufferedImage;
import com.ermapper.ecw.JNCSRenderer;
import com.ermapper.ecw.JNCSProgressiveUpdate;

public class Example4 extends Applet implements JNCSProgressiveUpdate {

  boolean isStandalone = false;
  JNCSRenderer ecwRenderer = null;
  boolean bErrorOnOpen = false;
  String errorMessage = null;
  double dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY;
  int bandlist[];

  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }

  //Construct the applet
  public Example4() {
  }

  //Initialize the applet
  public void init() {
    try {
      String fileName = "C:\\Program Files\\Earth Resource Mapping\\ECW Java SDK 2.45\\testdata\\Greyscale.ecw";

      // Create a renderer in progressive image mode.
      ecwRenderer = new JNCSRenderer(fileName, true);

      // Inform the client that we want updates
      ecwRenderer.addProgressiveUpdateListener(this);

      // Setup the view parameters for the ecw file.
      bandlist = new int[ecwRenderer.numBands];
      for (int i=0; i< ecwRenderer.numBands; i++) {
        bandlist[i] = i;
      }
      dWorldTLX = ecwRenderer.originX;
      dWorldTLY = ecwRenderer.originY;
      dWorldBRX = ecwRenderer.originX + (double)(ecwRenderer.width-1)*ecwRenderer.cellIncrementX;
      dWorldBRY = ecwRenderer.originY + (double)(ecwRenderer.height-1)*ecwRenderer.cellIncrementY;
    }
    catch(Exception e) {
      errorMessage = e.getMessage();
      bErrorOnOpen = true;
    }
  }

  public void setBounds(int tlx, int tly, int width, int height) {

    super.setBounds(tlx, tly, width, height);

    if (ecwRenderer == null) {
      return;
    }

    // Work out the correct aspect for the draw call.
    double dFileAspect, dWindowAspect;
    dFileAspect = (double)ecwRenderer.width/(double)ecwRenderer.height;
    dWindowAspect = (double)getWidth()/(double)getHeight();

    if (dFileAspect > dWindowAspect) {
      height =(int)((double)width/dFileAspect);
    } else {
      width = (int)((double)height*dFileAspect);
    }

    try {
      ecwRenderer.setView(ecwRenderer.numBands, bandlist, dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, width, height);
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }

  //Start the applet
  public void start() {
  }

  //Stop the applet
  public void stop() {
  }

  //Destroy the applet
  public void destroy() {
  }

  //Get Applet information
  public String getAppletInfo() {
    return "JNCSFile Example4.";
  }

  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }

  //Main method
  public static void main(String[] args) {
    Example4 applet = new Example4();
    applet.isStandalone = false;
    Frame frame;
    frame = new Frame() {

      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }

      public synchronized void setTitle(String title) {
        super.setTitle(title);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      }
    };
    frame.setTitle("JNCSFile Example 4");
    frame.add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(400,320);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
  }

  public void paint(Graphics g) {

    if (bErrorOnOpen) {
      g.drawString(errorMessage, 0, 50);
    }
    else {
      double dFileAspect, dWindowAspect;
      int width = getWidth(), height = getHeight();
 
      // Work out the correct aspect for the draw call.
      dFileAspect = (double)ecwRenderer.width/(double)ecwRenderer.height;
      dWindowAspect = (double)getWidth()/(double)getHeight();

      if (dFileAspect > dWindowAspect) {
        height =(int)((double)width/dFileAspect);
      } else {
        width = (int)((double)height*dFileAspect);
      }

      // Draw the all available imagery to the screen.
      ecwRenderer.drawImage(g, 0, 0, width, height, dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, this);
    }
  }

  public void refreshUpdate(int nWidth, int nHeight, double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY) {
    repaint();
  }

  public void refreshUpdate(int nWidth, int nHeight, int dDatasetTLX, int dDatasetTLY, int dDatasetBRX, int dDatasetBRY) {
  }

}
```

Also i am using a jar file called ermapper.jar which is a signed jar and i have wriiten in the APPLET tag of my html file which is listed below


```
applet code="Example4.class" name="ecw" width="4000" height="320" archive = "ermapper.jar" id="ecw"
```

thanks in advance,

Markus


Edit: please use code-tags


----------



## Spacerat (1. Mrz 2005)

Hi Markus... You are in a german environment here. I'll give my best to help you.

Between your Codelines 30 and 35, you use the "file"-Protocol which is not allowed for an unsigned Applet (i.E. C:\\ ...). You have to load the File (if possible) with the "http"-protocol. The file has to be placed in the Applets Doc- or CodeBase drawer.

cu Spacerat


----------



## Guest (1. Mrz 2005)

Spacerat hat gesagt.:
			
		

> Hi Markus... You are in a german environment here. I'll give my best to help you.
> 
> Between your Codelines 30 and 35, you use the "file"-Protocol which is not allowed for an unsigned Applet (i.E. C:\\ ...). You have to load the File (if possible) with the "http"-protocol. The file has to be placed in the Applets Doc- or CodeBase drawer.
> 
> cu Spacerat



Hallo Spacerat,
erst mal Danke für deine Antwort und entschuldige dass ich auf english mein Problem beschrieben habe.
Nach so viel Jahren Aufenthalt im Deutchland kann ich mich  immer noch besser in English  artikulieren als in Deutsch(LEIDER!!) . 

Aber zurück zu meinem Problem,
Das Problem existert auch noch wenn man einen Relativen Adresse eingibt z.B. sowas wie "./Greyscale.ecw"
kann man trotzdem noch sagen dass das Problem mit "http"-protocol ezwas zutun hat ??

Mit freundlichen Grüßen
Markus


----------



## Spacerat (1. Mrz 2005)

Ist es möglich, das die Datei oberhalb der Applet-Document-Base oder gar auf einem anderen Server liegt?


----------



## Kian (3. Mrz 2005)

> "The security manager has denied loading of native libraries. Only trusted classes and signed JAR files can access native libraries".



Try signing your Applet, this will solve your problems. I think!

http://personal.vsnl.com/sureshms/javasign1.html


----------

