What is getResources ?

public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
    throws Exception {
              MessageResources messages = getResources(request); // question-1
        ActionErrors errors = new ActionErrors();
        String person = (String) PropertyUtils.getSimpleProperty(form, "person");
        String badPerson = "Atilla the Hun";
        if (person.equals(badPerson)) {
            errors.add("person",
               new ActionError("ch03.hello.dont.talk.to.atilla", badPerson ));
                  saveErrors(request, errors);
                  return (new ActionForward(mapping.getInput()));
        }question-1 : what is getResources(request) ? is it defined in the Struts somewhere ? where it is defined ?

in case you have questions abit these kinds of things then i suggest you always follow next procedure:
Open your favourite search engine
type in API and the classname and some extra info if possible
open first match
read it
example:
http://www.google.be/search?hl=nl&q=struts+api+Action&meta=
gives
http://struts.apache.org/struts-doc-1.2.7/api/org/apache/struts/action/Action.html
when you read this you will find the info you need

Similar Messages

  • What kind of path should be used in a *portable* .getResource()?

    I am porting to NetBeans an application that was running fine under JBuilder. There is one type of statement that refuses to be ported (getResource()).
    The application contains a lot of lines like this:
    url = AnnualReportsDialog.class.getResource("images/CheckMark.gif");Even the JBuilder tutorial has the same kind of file access relative to some current or default directory:
    ImageIcon image1 = new
    ImageIcon(hello_world.HelloWorldFrame.class.getResource("openFile.png"));When the "url" line above is reached, the getResource() fails.
    I have tried several variations:
    url = AnnualReportsDialog.class.getResource("C:\\images\\CheckMark.gif");
    url = AnnualReportsDialog.class.getResource("C:/images/CheckMark.gif");but they don't work.
    Perhaps something has changed between JRE 1.4 and 1.6?
    What is the more general solution to the problem of Java not having a 'chdir()'? My app runs on Windows but I would like to run in in *ix as well.
    Is there a way to place all those GIFs in some sort of resource, that can be carried around different O/Ss and filesystem paths? I would like the following to work under any OS:
    getResource("images/CheckMark.gif");
    TIA,
    -Ramon

    X-FI PCI 32Bit Cards?with 33MHz will fit into a PCi 64Bit slot. (The Slots must only support PCI 2.2 or later.)?Even a PCI-X slot can dri've PCI 32 33MHz cards. Downside: the PCI bridge will clock down all connectet PCI slots to 33MHz. Most PCI 64Bit slots supports 66MHz clock speed.
    Older PCI cards like Audigy will run in a 2. or lower?compatible PCI Slot.
    Message Edited by fffcmad on 03-26-2008 0:3 PM

  • What does MyClass.class.getClassLoader().getResource() do?

    Um. . .ok, I'm having a LD moment here. . .
    What does this java statement do?
    MyClass.class.getClassLoader().getResource("scripts").getPath() ;

    Here's the error from the log:
    java.lang.NullPointerException
         at com.oneok.dbLoader.scripts.OngDailyScriptLoader.getScripts(OngDailyScriptLoader.java:46)
         at com.oneok.dbLoader.scripts.OngDailyScriptLoader.Run(OngDailyScriptLoader.java:465)
         at com.oneok.dbLoader.scripts.OngDailyScriptLoader.run(OngDailyScriptLoader.java:494)
         at org.apache.jsp.runScript_jsp._jspService(runScript_jsp.java:52)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Unknown Source)

  • Using GetResource to get a file from a different folder than bin

    Hi guys,
    here is the line of code I am working with:
    final static URL musicD = Sound.class.getResource("Sound//MusicD.mid")this loads MusicD.mid from the project/bin/Sound folder. However, SVN messes up my bin folder badly, how can I get a resource from the project folder, or better yet project/sound folder as opposed to the bin folder? Thanks!
    P.S. I am on a tight deadline, so a straight answer would be very helpful, what I dont need is more smug advice! =) thanks!

    hiwa wrote:
    Christ_Guard wrote:
    Hi guys,
    here is the line of code I am working with:
    final static URL musicD = Sound.class.getResource("Sound//MusicD.mid")this loads MusicD.mid from the project/bin/Sound folder. However, SVN messes up my bin folder badly, how can I get a resource from the project folder, or better yet project/sound folder as opposed to the bin folder? The syntax is wrong. Besides, what is your current current directory from where your application is launched? Is it in a jar file?Thanks for the honest help, I really appreciate it! I am working out of eclipse and compiling it there, so it is not yet a jar file. How would you suggest fixing the syntax to work?
    P.S.
    the directory I am working from is this:
    C:\Users\Christian\TCSS 305 Workspace\shielc-tetristhis directory has the src and bin directories, yet I dont know how to get the resources from this directory instead of the bin directory.

  • Why getResource of jar in classpath returns null?

    When i iterate through the jars in the classpath and try to turn them into URL's via the getResources(), they all return null. What am I doing wrong?
    (NOTE: It does print out the classpath properly when i print that out)
    String classPath = System.getProperty( "java.class.path" );
    String delim = System.getProperty( "path.separator" );
    String[] locations = classPath.split( delim );
    for ( int i = 0; i < locations.length; i++ )
          /* ** It doesn't work with either of these statments: ** */
          //This one tries the full path (e.g. /home/me/test/some.jar)
          //Enumeration en = getClass().getClassLoader().getResources( locations[ i ].substring( locations[ i ] );
          //This one tries to use just the local name of the jar (e.g. test.jar)
          Enumeration en = getClass().getClassLoader().getResources( locations[ i ].substring( locations[ i ].lastIndexOf( '/' ) + 1 ) );
          //This just prints null
          while (  en.hasMoreElements(); ) System.out.println( en.nextElement() );
    }Edited by: 6tr6tr on Dec 4, 2008 5:46 PM
    Edited by: 6tr6tr on Dec 4, 2008 5:47 PM

    What you are doing doesn't make sense. The resource locations within a JAR file are relative to the package directory structure within the JAR file, not to its own absolute location on the disk. And you seem to be expecting to retrieve a JAR file from within a JAR file. This makes no sense either.

  • Offline running - can "GetResources() for an embedded file ever work?

    This question has come up in various guises in the past, but has often then become confused with other issues (see [t-5123126] ) so I've not been able to find a useful answer. I've tried to bring the problem down to the essentials, and just want to know if what I'm trying to do can ever work, or if I should just abandon Web Start for this particular need.
    Our app is J2SE Swing and creates a Derby database locally on a PC. The application then captures keyed data and stores it on the local database. Persistence is via JPA (provider was Toplink, now EclipseLink).
    The data capture is performed using laptops running the application "offline" with no network connection. This is because the location has no network access of any description. Periodically, each laptop is reconnected to upload its data to a central server.
    To help with software distribution, we are using Java Web Start. All the jars are signed and the .jnlp file specifes offline usage is allowed.
    When running the application while connected to the network, there are no issues - everything works fine.
    When running offline, the application starts up so the Java Web Start caching is working and the code is obviously accessible. However, it throws a MalformedURLException within the EclipseLink code (which we do not wish to modify). The actual statement is:
    Enumeration resources = classLoader.getResources("META-INF/persistence.xml"); META-INF/persistence.xml exists within one of the jar files specified as resources in the .jnlp file.
    The classloader in question is the Java Web Start classloader ( com.sun.jnlp.JNLPClassLoader) which presumably retrieves classes and resources from the remote server or from the cache depending on how the app is being run. In online mode, the persistence.xml resource is found ok, in offline a MalformedURLException is thrown.
    My question: is this a fundamental "restriction" of the Web Start environment in offline mode? i.e. it can't load resources such as this xml file from a cached jar using the format shown?. My feeling is that this is just the way it is, and I should move on and try another form of software distribution, but it seems a shame to abandon Web Start as it otherwise meets our needs.
    Any relevent experience of this problem would be appreciated.
    Edited by: GrayMan on Aug 21, 2009 8:20 AM

    A system we're developing make use of a similar setup. I'm not sure if you run into this problem, but the classes in our app uses persistence annotations and do not rely on the orm.xml mapping file. After solving the persistence.xml show stopper, I could see that the application had really slow startup times in offline mode. By looking at the access logs in online mode, I could see that the app was requesting META-INF/orm.xml and META-INF/eclipselink-orm.xml. In online mode, the web server simply returned HTTP 404 with much delay. In offline mode, this resulted in really slow startup times due to timeouts for the mentioned requests.
    Creating valid xml files bundling them into the jar file of course didn't help.
    I successfully disabled lookup for eclipselink-orm.xml by specifying the following entry in persistence.xml:
    <property name="eclipselink.exclude-eclipselink-orm" value="true"/>
    To disable lookup for orm.xml, I modified the method loadStandardMappingFiles(String) in org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.MetadataProcessor (eclipselink 1.1.0).
    Perhaps this is useful for someone else also.

  • What is the best practise to provide a text file for a Java class in a OSGi bundle in CQ?

    This is probably a very basic question so please bear with me.
    What is the best way to provide a .txt file to be read by a Java class in a OSGi bundle in CQ 5.5?
    I have been able to read a file called "test.txt" that I put in a structure like this /src/resources/<any-sub-folder>/test.txt  from my java class  at /src/main/java/com/test/mytest/Test.java using the bundle's getResource and getEntry calls but I was not able to use the context.getDataFile. How is this getDataFile method call to be used?
    And what if I want to read the file located in another bundle, is it possible? or can I add the file to some repository and then access it - but I am not clear how to do this.
    And I would also like to know what is the best practise if I need to provide a large  data set in a flat file to be read by a Java class in CQ5.
    Please provide detailed steps or point me to a how to guide or other helpful resources as I am a novice.
    Thank you in advance for your time and help.
    VS

    As you can read in the OSGi Core specification (section 4.5.2), the getDataFile() method is to read/write a file in the bundle's private persistent area. It cannot be used to read files contained in the bundle. The issue Sham mentions refers to a version of Felix which is not used in CQ.
    The methods you mentioned (getResource and getEntry) are appropriate for reading files contained in a bundle.
    Reading a file from the repository is done using the JCR API. You can see a blueprint for how to do this by looking at the readFile method in http://svn.apache.org/repos/asf/jackrabbit/tags/2.4.0/jackrabbit-jcr-commons/src/main/java /org/apache/jackrabbit/commons/JcrUtils.java. Unfortunately, this method is not currently usable as it was declared incorrectly (should be a static method, but is an instance method).
    Regards,
    Justin

  • What's wrong with my component?

    i make a new component which is a dragable icon here is my piece of code
    //class: DragAbleComponent.the father of my component
    import java.awt.Graphics;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import javax.accessibility.Accessible;
    import javax.swing.JComponent;
    public abstract class DragAbleComponent extends JComponent implements MouseListener,
              FocusListener, Accessible ,MouseMotionListener{
         private int X;
         private int Y;
         private static final long serialVersionUID = 1L;
         public void mouseClicked(MouseEvent e) {
              this.requestFocusInWindow();
         public void mouseEntered(MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}
         public void mousePressed(MouseEvent e) {}
         public void mouseReleased(MouseEvent e) {}
         public void focusGained(FocusEvent e) {
              this.repaint();}
         public void focusLost(FocusEvent e) {
         this.repaint();}
         protected abstract void paintComponent(Graphics graphics);
         public int getX() {
              return X;
         public void setX(int x) {
              X = x;
         public int getY() {
              return Y;
         public void setY(int y) {
              Y = y;
    //class:DragableIcon the component
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.InputEvent;
    import java.awt.event.MouseEvent;
    import javax.swing.Action;
    import javax.swing.ActionMap;
    import javax.swing.InputMap;
    import javax.swing.JComponent;
    import javax.swing.KeyStroke;
    import javax.swing.TransferHandler;
    public class DragableIcon extends DragAbleComponent {
         private Image image;
         private MouseEvent firstMouseEvent = null;
         private static boolean installKeyBordMapings = true;
         private static final long serialVersionUID = 1L;
         public DragableIcon(Image image) {
              super();
              this.image = image;
              this.setFocusable(true);
              this.addMouseListener(this);
              this.addFocusListener(this);
              this.addMouseMotionListener(this);
              this.initKeyBordMaping();
         private void initKeyBordMaping(){
              if (installKeyBordMapings) {
         InputMap imap = this.getInputMap();
    //     imap.put(KeyStroke.getKeyStroke("ctrl X"),
    //     TransferHandler.getCutAction().getValue(Action.NAME));
         imap.put(KeyStroke.getKeyStroke("ctrl C"),
         TransferHandler.getCopyAction().getValue(Action.NAME));
         imap.put(KeyStroke.getKeyStroke("ctrl V"),
         TransferHandler.getPasteAction().getValue(Action.NAME));
              ActionMap map = this.getActionMap();
    //     map.put(TransferHandler.getCutAction().getValue(Action.NAME),
    //     TransferHandler.getCutAction());
         map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
         TransferHandler.getCopyAction());
         map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
         TransferHandler.getPasteAction());
         @Override
         protected void paintComponent(Graphics graphics) {
              Graphics g = graphics.create();
         //Draw in our entire space, even if isOpaque is false.
         g.setColor(Color.WHITE);
         g.fillRect(0, 0, image == null ? 125 : image.getWidth(this),
         image == null ? 125 : image.getHeight(this));
         if (image != null) {
         //Draw image at its natural size of 125x125.
         g.drawImage(image, 0, 0, this);
         //Add a border, red if picture currently has focus
         if (isFocusOwner()) {
         g.setColor(Color.RED);
         } else {
         g.setColor(Color.BLACK);
         g.drawRect(0, 0, image == null ? 125 : image.getWidth(this),
         image == null ? 125 : image.getHeight(this));
         // g.drawImage(image, 0, 0, this);
         g.dispose();
         public void mouseDragged(MouseEvent e) {
    //Don't bother to drag if the component displays no image.
    if (image == null) return;
    if (firstMouseEvent != null) {
    e.consume();
    //If they are holding down the control key, COPY rather than MOVE
    int ctrlMask = InputEvent.CTRL_DOWN_MASK;
    int action = ((e.getModifiersEx() & ctrlMask) == ctrlMask) ?
    TransferHandler.COPY : TransferHandler.MOVE;
    int dx = Math.abs(e.getX() - firstMouseEvent.getX());
    int dy = Math.abs(e.getY() - firstMouseEvent.getY());
    //Arbitrarily define a 5-pixel shift as the
    //official beginning of a drag.
    if (dx > 5 || dy > 5) {
    //This is a drag, not a click.
    JComponent c = (JComponent)e.getSource();
    TransferHandler handler = c.getTransferHandler();
    //Tell the transfer handler to initiate the drag.
    handler.exportAsDrag(c, firstMouseEvent, action);
    firstMouseEvent = null;
         public void mouseMoved(MouseEvent e) {}
         public void mousePressed(MouseEvent e) {
         //Don't bother to drag if there is no image.
         if (image == null) return;
         firstMouseEvent = e;
         e.consume();
         public void mouseReleased(MouseEvent e) {
         firstMouseEvent = null;
         public static boolean isInstallKeyBordMapings() {
              return installKeyBordMapings;
         public static void setInstallKeyBordMapings(boolean installKeyBordMapings) {
              DragableIcon.installKeyBordMapings = installKeyBordMapings;
         public Image getImage() {
              return image;
         public void setImage(Image image) {
              this.image = image;
    //and here is my pane
    import java.awt.BorderLayout;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import javax.swing.JToolBar;
    import cn.com.ynld.bms.applet.gui.handler.IconTransferHandler;
    import cn.com.ynld.bms.applet.service.TransfAble;
    import cn.com.ynld.bms.applet.service.UpdateAble;
    public class ElectronicPane extends JPanel
                                                                                    implements ItemListener,UpdateAble{
    private UpdateAble updateAble = null;
    private ScrollAbleImage image;
    private JToolBar toolBar;
    private IconTransferHandler handler;
         private static final long serialVersionUID = 1L;
         public ElectronicPane(){
              super(new BorderLayout());
              handler = new IconTransferHandler();
         this.creatToolBar();
         this.add(this.toolBar);
         this.setTransferHandler(handler);
         public void itemStateChanged(ItemEvent e) {}
         public void addTransferAble(String key, TransfAble transferAble) {
              // TODO
         public TransfAble getTransferAble(String key) {
              // TODO
              return null;
         public void removeTransferAble(String key) {
              this.updateAble.removeTransferAble(key);
         public void update(UpdateAble updateAble) {
              this.updateAble = updateAble;
              this.init();
         private void init(){
              this.image = new ScrollAbleImage();
              this.image.update(updateAble);
              this.add(image,BorderLayout.CENTER);
              this.repaint();
              //this.image.repaint();
         private void creatToolBar(){
              this.toolBar = new JToolBar();
              DragableIcon alarm = new DragableIcon(createImageIcon("/root/Desktop/drawing/png-0003.png", "alarm").getImage());
              alarm.setTransferHandler(handler);
              DragableIcon damage = new DragableIcon(createImageIcon("/root/Desktop/drawing/png-0007.png", "device").getImage());
              alarm.setTransferHandler(handler);
              this.toolBar.add(alarm);
              this.toolBar.addSeparator();
              this.toolBar.add(damage);
              this.toolBar.setFloatable(false);
         /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path,
    String description) {
    // java.net.URL imageURL = DragPictureDemo.class.getResource(path);
    if (path == null) {
    System.err.println("Resource not found: "
    + path);
    return null;
    } else {
    return new ImageIcon(path, description);
    the problem is i add DragableIcons to my toolbar but only the first icon can be seen!!!!
    what's wrong
    thanks for any help!

    what's wrong
        private void creatToolBar() {
            this.toolBar = new JToolBar();
            ImageIcon alarm = createImageIcon(
                                  "/root/Desktop/drawing/png-0003.png",
                                  "alarm");
    //        alarm.setTransferHandler(handler);
            // register icon with its Action
            alarmAction.putValue(Action.SMALL_ICON, alarm);
            ImageIcon damage = createImageIcon(
                                   "/root/Desktop/drawing/png-0007.png",
                                   "device");
    //        damage.setTransferHandler(handler);
            // set the icon to the Action that will use it
            damageAction.putValue(Action.SMALL_ICON, damage);
            // toolBars are equipped to receive an Action or JComponent
            // they don't know what to do with ImageIcons
            this.toolBar.add(alarmAction);
            this.toolBar.addSeparator();
            this.toolBar.add(damageAction);
            this.toolBar.setFloatable(false);
        /** Returns an ImageIcon, or null if the path was invalid. */
        protected static ImageIcon createImageIcon(String path, String description) {
            // Use the containing class name. This works for static context in
            // which the "this" keyword does not work.
            // Otherwise, you could simply use getResource.
            java.net.URL imageURL = ElectronicPane.class.getResource(path);
            if (path == null) {
                System.err.println("Resource not found: " + path);
                return null;
            } else {
                return new ImageIcon(path, description);
        private Action alarmAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                Toolkit.getDefaultToolkit().beep();
        private Action damageAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("damage action");
        };

  • Trying to understand the getResource method

    Hi!
    I'm writing a simple game and I'm using a game framework for java. The framework uses the getResource("path") method on creating every texture. The constructor only accepts the relative path. My problem is I don't want image files to be placed in the build folder. I would like to create textures from an absolute path. I don't want to modify the framework code.
    In the Class Loader javadoc I've found that getResorce method executes the findResorce method if it fails on finding the resource. The findResource method should be overriden in a Class Loader implementation. How can I do it?
    Thanks.

    morgalr wrote:
    tom_ex wrote:
    Hi!
    I'm writing a simple game and I'm using a game framework for java. The framework uses the getResource("path") method on creating every texture. The constructor only accepts the relative path. My problem is I don't want image files to be placed in the build folder. I would like to create textures from an absolute path. I don't want to modify the framework code.
    In the Class Loader javadoc I've found that getResorce method executes the findResorce method if it fails on finding the resource. The findResource method should be overriden in a Class Loader implementation. How can I do it?
    Thanks.It does this so you can JAR your application, which gives you the ability to distribute an executable with all of your resources included. So your buds will not have to worry about if they have the support files installed to run your application or not.I understand the intention, but it's rather an opposite of what I'm trying to do. In my idea the game on it's first running aks the user for a path. The path points a place where the sounds and images should by downloaded i.e. from an ftp server. On the later runnings the game already know where the images, etc have been downloaded and uses them.

  • What's the maximum size.......

    What's the maximum size of an ImageIcon to be supported by a Label???
    I'm trying to show a 3.5 Mb image and doesn't show it. But a 1 Mb does....
    Can anyone tell me why this happens???

    Well maybe you have to set the size of the Label to the size of the Image - use setPreferredSize() to set the size of the label....
    otherwise you can do something like this :
    //Get the Icon
    icon =
    new ImageIcon(YourFrame.class.getClassLoader().getResource(
                   "/images/yourImage"));
    //Get he Width of the Label on which the Image is placed
    int width = imageLabel.getSize().width;
    //Get the height of the label on which the Image is placed
    int height = imageLabel.getSize().height;
    //Get the Scaled image
    Image scaledImage = image.getScaledInstance(width,height,Image.SCALESMOOTH);
    //Set the Image of the Icon
    icon.setImage(scaledImage);
    //Update the Image Label
    imageLabel.updateUI();
    --j                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • What is the command to verify the configuration that are not saved or sent to local controllers?

    Q: What is the command to verify the configuration that are not saved or sent to local controllers?
    A: We can execute the command that is shown in below image to check the status of the configuration that has been made.
    Note: For example I made changes to the default VAP profile and executed the command "show master-configpending" which shows the pending configuration to be saved/sent to local controllers.

    But that jar file loads without images and icons when it is in other directory.Images should be accessed via a URL rather than using a filename because they will exist as entries in the jar archive not as files. Typically this URL would be obtained by using the Class method [getResource()|http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResource(java.lang.String)]. There are details in this [Java World article|http://www.javaworld.com/javaworld/javaqa/2002-11/02-qa-1122-resources.html].

  • What is the exact mean of  classname.class.

    what is the exact mean of classname.class. what situations it will be use ful . how to use . give me one example .

    Each class, interface, or enum loaded into the JVM has an associated Class object. This contains a lot of information about the class in question, including lists of fields and methods. <classname>.class gives you a reference to the Class object of the class mentioned.
    See the java.lang.Class javadocs for all the things you can do with a Class object.
    For example:
    theImage = new ImageIcon(MainClass.class.getResource("item.png"));to retrieve an image file from the directory containing the MainClass class file.

  • GetResource is called when document root is not set

    hi,
    During redeploy of a small application i get the following error
    [runjava] <Oct 17, 2005 12:40:26 AM PDT> <Alert> <HTTP> <BEA-101043> <[ServletContext(id=616697,name=rsbservice,context-pat
    h=/rsbservice)] getResource is called when document root is not set.>
    [runjava] <Oct 17, 2005 12:40:26 AM PDT> <Alert> <HTTP> <BEA-101043> <[ServletContext(id=616697,name=rsbservice,context-pat
    h=/rsbservice)] getResource is called when document root is not set.>
    Can someone help me find what would have gone wrong in my application?
    NOTE: this error does not occur when i try to start my application for the first time.

    You must always give the browser an either an absolute URL from the top of
              the web server (not the
              web application) or a relative path from the current page.
              Sam
              "Vijay Kumar" <[email protected]> wrote in message
              news:[email protected]..
              > Hi
              >
              > I get the 'getResource is called when document root is not set.' error
              > when I access any files in the webapp with their absolute path.
              >
              > Environment: WIN/NT SP3, WL5.1 SP5 as the webserver and app server.
              >
              > My webapp located in d:\temp is deployed as foo
              > weblogic.httpd.webApp.foo=d:/temp
              >
              > For example:
              > I can access a file in d:\temp\secured\home.html using
              > test
              >
              > However if with in an html I try to access the file using the abs path
              > from doc root
              > test I get an error
              >
              > and I guess the default servlet looks for the servlet-context named
              > 'secured'
              >
              > Can someone tell me if I can set the documentRoot in the web.xml or
              > weblogic.xml
              > file OR if there is any other way to access to the file using the abs path
              > of /secured/test/test.html
              >
              >
              > Thanks in advance
              >
              > Vijay
              >
              >
              >
              >
              

  • Jframe seticonimage; what is this error?!

    java.net.URL imgURL = this.class.getResource("images/FD.jpg");
            if (imgURL != null) {
                this.setIconImage(new ImageIcon(imgURL).getImage());
            } else {
                System.out.println("not found");
            }THE ERROR
    \DefaultFrame.java:35: <identifier> expected
    java.net.URL imgURL = this.class.getResource("images/FD.jpg");
    what am i doing wrong?!!!?
    the DefaultFrame class extends JFrame

    You can use the object methodthis.getClass() or the class variableYourClassName.classto get the class object for a class (as you found out).
    I think to solve your particular issue, use the first version I quoted above, and make sure the images folder is in the same folder as your class file.
    Regards,
    Tim

  • I don't know what to do anymore! Background Image is not displayed???!!!

    Hey there!
    I'm just trying to show a simple jpg in the Background Layer and it does not seem to work! I really need this for my diploma and i do not know where i made the mistake and it is compiling without errors!! Yet the picture is not shown.. Could somebody help me please? Any answer would be very helpful for me for i don't know what to do anymore..I am testing my Xlets with XletView 3.6..
    Here is the code i tried:
    public class BackgroundImage extends HComponent implements Xlet, Runnable{
    private HScene scene;
    private Image image;
    private HaviBackgroundController backgroundManager;
    private XletContext context;
    private Thread myWorkerThread;
         public BackgroundImage()
    public void initXlet(XletContext context) throws
    javax.tv.xlet.XletStateChangeException
              this.context = context;
    public void startXlet() throws javax.tv.xlet.XletStateChangeException
         myWorkerThread = new Thread(this);
              myWorkerThread.start();
    public void pauseXlet()
              pause();
    public void destroyXlet(boolean unconditional) throws javax.tv.xlet.XletStateChangeException
              if (unconditional) {
                   destroy();
    public void run()
              getResources();
              showBackgroundImage();
    public void getResources() {
    HSceneFactory factory = HSceneFactory.getInstance();
    HSceneTemplate hst = new HSceneTemplate();
    hst.setPreference(
    HSceneTemplate.SCENE_SCREEN_DIMENSION,
                   new org.havi.ui.HScreenDimension(1,1),
                   HSceneTemplate.REQUIRED);
              hst.setPreference(
    HSceneTemplate.SCENE_SCREEN_LOCATION,
                   new org.havi.ui.HScreenPoint(0,0),
                   HSceneTemplate.REQUIRED);
    scene = factory.getBestScene(hst);
    Rectangle rect = scene.getBounds();
    setBounds(rect);
    setVisible(true);
    setBackground(Color.black);
    scene.add(this);
    scene.setVisible(true);
    this.requestFocus();
    public void showBackgroundImage() {
    MediaTracker tracker = new MediaTracker(this);
    image = Toolkit.getDefaultToolkit().getImage("background.jpg");
    tracker.addImage(image, 0);
    try{
                   tracker.waitForAll();
              catch(InterruptedException e) {
                   image = null;
              backgroundManager = new HaviBackgroundController();
              if (backgroundManager.init()) {
         backgroundManager.display("background.jpg");
    public void pause()
    scene.setVisible(false);
         backgroundManager.dispose();
    public void destroy()
    scene.setVisible(false);
    scene.remove(this);
    image.flush();
    image = null;
    backgroundManager.dispose();
    HSceneFactory.getInstance().dispose(scene);
    scene = null;
    }

    Sorry, i forgot about that..
    I tried the HaviBackgroundController Class of Steve Morris (thanks a lot for that great Tutorial!). It is as follows:
    class HaviBackgroundController implements ResourceClient{
    private HBackgroundDevice backdevice;
    private HStillImageBackgroundConfiguration backconfig;
    public boolean init()
    HScreen screen = HScreen.getDefaultHScreen();
    HBackgroundDevice backdevice = screen.getDefaultHBackgroundDevice();
    HBackgroundConfigTemplate backgroundConfigurationTemplate = new
              HBackgroundConfigTemplate();
    backgroundConfigurationTemplate.setPreference(
    HBackgroundConfigTemplate.FLICKER_FILTERING,
                   HBackgroundConfigTemplate.REQUIRED);
              HBackgroundConfiguration backconfig;
              backconfig = backdevice.getBestConfiguration(
                   backgroundConfigurationTemplate);
              if (backdevice.reserveDevice(this))
                   try
                        backdevice.setBackgroundConfiguration(backconfig);
                   catch (Exception ex)
                        System.out.println("Can't initialise the background device");
                        backdevice.releaseDevice();
                        return false;
                   if(backconfig instanceof HStillImageBackgroundConfiguration)
                        this.backconfig = (HStillImageBackgroundConfiguration)backconfig;
                        this.backdevice = backdevice;
                        return true;
                   else
                        backdevice.releaseDevice();
              return false;
         public void dispose()
              if (backdevice != null)
                   backdevice.releaseDevice();
                   backdevice = null;
                   backconfig = null;
         public void display(String filename)
              if(backconfig != null) {
                   HBackgroundImage backimage = new HBackgroundImage("background.jpg");
                   try {
                        backconfig.displayImage(backimage);
                   catch (java.io.IOException ioe) {
                        System.out.println("Can't display background image - IO exception");
                        ioe.printStackTrace();
                   catch (HPermissionDeniedException hpde) {
                        System.out.println("Can't display background image - permission denied");
                   catch (HConfigurationException hce) {
                        System.out.println("Can't display background image - configuration exception");
                        hce.printStackTrace();
         public boolean requestRelease(ResourceProxy proxy, Object requestData) {
              return false;
         public void release(ResourceProxy proxy) {
              backdevice.releaseDevice();
         public void notifyRelease(ResourceProxy proxy) {
              backdevice.releaseDevice();
    }

Maybe you are looking for

  • CD Burn Fail. Error 4280

    The attempt to burn a disk failed. An unknown error occured. 4280 How do I fix this? What does it mean? Diagnostics is able to read and report the drive and error. (Mashita UJ840D)

  • Missing "pre order points" for Shadow of Mordor.

    I've recently received Shadow of Mordor, I had the game pre ordered, but I'm positive that I didn't receive the 500 bonus points for pre ordering. I can't tell if they're pending or what with the new system, and I can't report those points missing th

  • Problem in running JCOM - License Exception

    Hi, I have checked all the previous links related to License. But i am not able to still find out the solution. Here are the following steps which i followed: (Plz check ) 1) To access the com object      Step 1 : I have written an active x dll and i

  • How can i unlock my phone i just bought

    i just bought an used phone off ebay at&t im trying to unlock my imei how can i go about this

  • Wrong file

    I have baught Final Cut Express HD and now I want to learn to use it. When I open a MPG movie file it says "File Error: Wrong type." What file should it be, and how do I change it?