Problem on getResourceAsStream

i need to acsses pass.dat file from resources folder
but it dose not working how can i solve this
try {
         FileInputStream fin=(FileInputStream) getClass().getResourceAsStream("/TestProg/resources/pass.dat");
        ObjectInputStream ois = new ObjectInputStream(fin);
         SecretKey key = (SecretKey) ois.readObject();
         ois.close();
        Encoder encrypter = new Encoder(key);
        encrypter.encrypt(new FileInputStream(filepath),new FileOutputStream(outputFilePath));
        System.out.println("File Encryption Completed !!!");
    } catch (Exception e) {
    }

Mrkarthick wrote:
i have Found This Exception
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.io.BufferedInputStream cannot be cast to java.io.FileInputStream
It would help if you'd provide the whole stack trace, and indicate exactly which line caused the problem, but I assume it's this one:
         FileInputStream fin=(FileInputStream) getClass().getResourceAsStream("/TestProg/resources/pass.dat");You can't just cast any old class to any old other class. You can only cast a reference to a type that the object it points to actually is.
In any case, you don't need a FileInputStream, since you're not dealing with a file here. Dealing with the file (if the resource even actually is in a file, rather than some other place, like on a web server) is handled for you inside getResourceAsStream.

Similar Messages

  • Problem with getResourceAsStream

    Hi,
    I ran into a problem with using getResourceAsStream. My application is packaged in an ear-file and consists of a WAR an EJB-JAR and multiple utility JARs. Everything deploys fine and I don't have any classloading problems, so the class-path settings in the MANIFEST-MF files seem to be fine.
    The problem starts when a stateless session bean tries to configure a part of the application by calling getResourceAsStream to retrieve the configuration xml file which is packaged in the same JAR file like the class which is calling getResourceAsStream. In every other app server I used so far, that's working perfectly fine. The JAR is even displayed in the list of the class loader and as I said, i can load classes from that JAR. But every time I try to load a resource file from that JAR, it fails. If I call getResource to get a URL object that works and gives me the URL to the desired file, but a load of that fails though.
    If I package the file into the WAR or the EJB-JAR getResourceAsStream will find it and hand it back.
    I'm absolutely puzzeled by this behavior and would greatly appretiate any hints to be able to read this resource file.
    Thanks...
    Andreas

    Let me try to answer both questions -- and thanks for all the help. The class is wihin a package and let me explain further...
    1) I'm testing outside the netbeans IDE by executing:
    java -jar MyJar.jar
    This works fine when I had the old version of the code:
    iStream = this.getClass().getResourceAsStream(strategyFile);
    However, then I have the previously noted problem of trying to run tests within the netbeans ide and not being able to find the test files unless they are included in the source package (non-test version).
    2) If I switch the code as suggested to:
    iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(strategyFile);
    Then the netbeans Junit tests function and can read the test files from the test package within the netbeans IDE when I execute the Junit tests. However, when I go outside the IDE and try
    java -jar MyJar.jar
    the default file is not found in the jar. I've checked the jar file and verified that data file is inside the jar via jar tf.

  • GetResourceAsStream problems Read(byte[])

    Heres my code. Some images show up fine, others dont show up at all, and others show up as black images when the images are in a jar file. All images show up fine when they are on the lcoal file system. All images DO fit in the ~60kb byte array. Any suggestions on what the problem is, I have worked around my problem but I would like to know what was going on. My work around was to loop inputstream.read() into the byte array and that has worked.
        public static ImageIcon GetImage(String fileName)
            InputStream iStream=null;
            ImageIcon ic = null;
            try
                if( classLoader == null )
                    try
                        classLoader = Class.forName( "myappclass" ).getClassLoader();
                    catch( Exception x)
                        System.out.println( x.toString() );
                        return ic;
                iStream = classLoader.getResourceAsStream( fileName );
                byte[] bytes = new byte[65000];
                iStream.read(bytes);
               //heres around where it goes caplooyey
                ic = new ImageIcon(bytes);
            catch (IOException ex)
    //            iStream.close();
                System.out.println("No existing file to copy");
                return ic;
            return ic;
        }

    Your code is reading the stream before all the data are available so one read will grab only a partial image. One solution would be to use a BufferedInputStream, but that would consume even more memory than your current approach.
    A much simpler, more efficient, and wholly equivalent technique is accomplished with this one line of code:
    ic = new ImageIcon(ClassLoader.getSystemResource(fileName));

  • GetResourceAsStream problem

    I am trying to read text file in a midlet but can not seem to do it. I'm using the wireless tool kit SDK and emulation with Borland JBuilder . I can run the midlet with no problem but can't seem to open the file. Here is a code snippet below. fin is always null, so I suspect that the file is in the wrong location. The directory sturcture is as follows
    -ProjectRoot<dir>
    test.dat<file>
    -src<sub-dir>
    MyMidlet.java<file>
    Can someone tell me where the file should go or what I'm doing wrong in the code? It seems so simple, I know I 'm missing something fundemental here.
    Thanks for your help!
    Cam
    public class MyMidlet extends MIDlet {
    static MyMidlet instance;
    Displayable1 displayable = new Displayable1();
    public MyMidlet() {
    instance = this;
    InputStream fin = this.getClass().getResourceAsStream("test.dat");//tried "/test.dat" as well
    if (fin == null) {
    System.out.println("Fin is Null");
    }else {
    System.out.println("Fin is FOUND");
    try {
    fin.close();
    } catch (IOException ex) {
    ......... other Midlet methods

    With the Wireless Toolkit resources need to be in a "res" subdirectory (at the same level as "src"), or else packaged up into a JAR file.

  • Class.getResourceAsStream problem

    how to write the path for class.getResourceAsStream() when the project folder and image folder are in different drive?
    For example my project folder is {color:#0000ff}D:\WorkDir\workspace\TryNew\WebContent\WEB-INF\src\com\NewsAndResearch\ImageDB.java,
    {color}my image folder is {color:#0000ff}C:\bea\alui\ptimages\imageserver\plumtree\bondinfo\abc.pdf .
    {color}{color:#000000}Hope someone can help me to solve this problem.
    {color}

    easy82 wrote:
    So if the resources is not in the classpath then it mean cant accessable?Correct.
    And got what solution for my case?Adding it to our classpath. Or better: do what people normally do and add web-app resources to your web-app.

  • GetResourceAsStream problem in a EJB JAR

    Hello,
    I am trying to get a xml file from the same JAR file my EJB's are
    bundled in on 6.1. Its not in the WAR file but the EJB jar file.
    I've been trying to use:
    getClass().getClassLoader().getResourceAsStream("www.xml")
    and various different versions of this (using "/www.xml')
    I've tried placing the xml file in the root of the JAR file and in the
    same package as the class. I get the impression that its always
    looking in the weblogic class path, and not the classloaders. (it
    works if I place the file in the Weblogic6.1 dir)
    Has anyone managed to retrieve file resources from their EJB JAR
    files? If so how?
    Thanks

    I do this by placing the resource file in it's own .jar file. Then place that .jar file in the .ear file with
    the ejb .jar files. Then put the resource .jar file in the classpath using the Class-Path: manifest directive
    in the ejb .jar files. Then you can use this.getClass().getResourceAsStream("/foo.xml") in the ejb bean
    class.
    I've never tried it by placing the resource file in the ejb .jar file. I would think it would work, but
    apparently not?
    Bill Kemp
    BEA
    Wayne wrote:
    Actually I tried this and it doesn't seem to work. I imagine its
    becuase the EJB classloader can't see the resources in the WAR file?
    Remember I'm trying to load the resource from an EJB JAR file not a
    WAR file.
    Any idea's how I could do this?
    thanks
    Rajesh Mirchandani <[email protected]> wrote in message news:<[email protected]>...
    If the file is in WEB-INF/classes within your WAR it should work if you
    execute
    this.getClass().getClassLoader().getResourceAsStream("www.xml");
    Wayne wrote:
    Hello,
    I am trying to get a xml file from the same JAR file my EJB's are
    bundled in on 6.1. Its not in the WAR file but the EJB jar file.
    I've been trying to use:
    getClass().getClassLoader().getResourceAsStream("www.xml")
    and various different versions of this (using "/www.xml')
    I've tried placing the xml file in the root of the JAR file and in the
    same package as the class. I get the impression that its always
    looking in the weblogic class path, and not the classloaders. (it
    works if I place the file in the Weblogic6.1 dir)
    Has anyone managed to retrieve file resources from their EJB JAR
    files? If so how?
    Thanks

  • ClassLoader.getResourceAsStream + Major problem  ;-)

    Hi,
    Please let me know what is worng with this application: I am getting compilation error. The method getResourceAsStream() is a non-static method.
    " non-static method func(java.lang.String) cannot be referenced from a static context"
    =============================================
    import java.io.* ;
    public class LoadProp
    public static void main(String args[])
    String testname = System.getProperty("propfile");
    System.out.println(testname);
    func(testname) ;
    System.out.println("End Main!") ;
    public void func(String file )
    try
    InputStream is = ClassLoader.getResourceAsStream(file);
    System.out.println("File load successful");
    catch (Exception e)
    System.out.println("Inside Catch");
    throw e;
    =====================================
    I also implemented the same by creating a new class as below:
    class Jms
    public void func(String file )
    try
    InputStream is = ClassLoader.getResourceAsStream(file);
    System.out.println("File load successful");
    catch (Exception e)
    System.out.println("Inside Catch");
    throw e;
    public class LoadProp
    public static void main(String args[])
    String testname = System.getProperty("propfile");
    System.out.println(testname);
    Jms j = new Jms() ;
    j.func(testname) ;
    System.out.println("End Main!") ;
    Please let me know what is worng with this application .
    Thanks
    N

    Thanx!
    One more doubt. :-D
    This class initially was having
    ClassLoader.getSystemResourceAsStream()
    As far as my understanding goes, if we go with this implementation, we need to set the CLASSPATH variable for loading a file used by the class.
    Then whats the difference between
    ClassLoader.getSystemResourceAsStream()
    ClassLoader.getResourceAsStream()
    Plz bear.
    N

  • A problem with Threads and MMapi

    I am tring to execute a class based on Game canvas.
    The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
    The MIDI tone "Stammers".
    How to over come the problem?
    Thanks in advance
    Kobi
    See Code example below:
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    public class MainScreenCanvas extends GameCanvas implements Runnable {
         private MainMIDlet parent;
         private boolean mTrucking = false;
         Image imgBackgound = null;
         int imgBackgoundX = 0, imgBackgoundY = 0;
         Player player;
         public MainScreenCanvas(MainMIDlet parent)
              super(true);
              this.parent = parent;
              try
                   imgBackgound = Image.createImage("/images/area03_bkg0.png");
                   imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
                   imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
              catch(Exception e)
                   System.out.println(e.getMessage());
          * starts thread
         public void start()
              mTrucking = true;
              Thread t = new Thread(this);
              t.start();
          * stops thread
         public void stop()
              mTrucking = false;
         public void play()
              try
                   InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
                   player = Manager.createPlayer(is, "audio/midi");
                   player.setLoopCount(-1);
                   player.prefetch();
                   player.start();
              catch(Exception e)
                   System.out.println(e.getMessage());
         public void run()
              Graphics g = getGraphics();
              play();
              while (true)
                   tick();
                   input();
                   render(g);
          * responsible for object movements
         private void tick()
          * response to key input
         private void input()
              int keyStates = getKeyStates();
              if ((keyStates & LEFT_PRESSED) != 0)
                   imgBackgoundX++;
                   if (imgBackgoundX > 0)
                        imgBackgoundX = 0;
              if ((keyStates & RIGHT_PRESSED) != 0)
                   imgBackgoundX--;
                   if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
                        imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
          * Responsible for the drawing
          * @param g
         private void render(Graphics g)
              g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
              this.flushGraphics();
    }

    You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
    However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
    You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
    Regds,
    SD
    N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
    Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM

  • Problem with my program looking for the settings file in the wrong folder

    I have been writing a simple FTP file uploader, what I want to do is be able to select the files I want to upload in windows explorer and then right click and click the menu item and it launches the program and passes the files paths that I have selected to it.
    So I use this in the windows registry "C:\Program Files\Java\jre1.6.0_03\bin\java.exe -jar D:\BenFTP\BenFTP.jar %1"
    It launches fine and has no problem finding the files I want to upload. The problem is that it tries to look for the settings file in the same folder that the file I am try to upload is in. Which it's not suppose to do since the settings file is in the same folder that the .jar is in.
    Edited by: ColNewman on Feb 5, 2008 6:55 PM

    So, you're looking for your settings file in your current working directory. There's no way to set the CWD in your registry entry (is there?) so that isn't a practical thing to do. Presumably you're using a File object or a FileReader or something? Can't do that.
    One alternative is to look for the settings file in the classpath. You can get a URL to a file in the classpath like this:URL settings = this.getClass().getResource("/settings.xml");Or you can get an InputStream to read the file by using the getResourceAsStream method. You would have to make sure that your executable jar file contained a Class-Path entry that specified the right directory, because the directory the jar is contained in isn't automatically in an executable jar's classpath.
    Another alternative is to ask the user where the settings file is supposed to be, and put an entry in the Preferences (java.util.prefs) to remember that location.

  • POI getCellStyle and empty string problem

    I'm having a problem getting the style of a cell from and excel input file and setting to an output file.
    I also have a problem recognizing blank cells that are not null in the input file here is my code any help would be great.
    package Trace;
    import java.io.*;
    import org.apache.poi.hssf.usermodel.*;
    import org.apache.poi.hssf.util.HSSFColor;
    import java.util.StringTokenizer;
    import org.apache.poi.poifs.filesystem.*;
    import java.lang.Runtime;
    public class Converter1 {
         private static short bhyvb= 0;
         private static short foreground, background;
         private static String[][] cellGridOut;
         private static int numRows, numColumns, clock;
         private static POIFSFileSystem fs;
         private static HSSFWorkbook wbin, wbout;
         private static HSSFSheet sheetIn, sheetOut;
         private static HSSFRow rowIn, rowOut;
         private static HSSFCell cellIn, cellIn1, cellOut;
         private static FileOutputStream fileOut = null;
         private static String rowIterator, rowIterator1;
         private static HSSFCellStyle style, style1;
         public static void main(String[] args) {
              //Take in 2 inputs mandatory, Input Event Trace excel file and Time Interval respectively
              if (args.length != 1)System.err.println("Input Excel File"); 
              //Create a new POI file system and HSSF workbook with your excel input file
              InputStream input = Converter.class.getResourceAsStream(args[0]);
              try{
                   fs = new POIFSFileSystem(input);
                   wbin = new HSSFWorkbook(fs);
              }catch (Exception e){System.err.println("File input error");}
              wbout = new HSSFWorkbook();
              sheetIn = wbin.getSheetAt(0);
              numRows = sheetIn.getLastRowNum();//numRows=723
              style = wbout.createCellStyle();
              //style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
              //style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
              //get number of columns
              rowIn = sheetIn.getRow(0);
              boolean done = false;
              int testNullPointer;
              numColumns=0;
              while(!done){
                   //System.out.println(ColumnInc);
                   cellIn = rowIn.getCell((short)numColumns);
                   numColumns+=1;
                   try{
                        testNullPointer = cellIn.getCellType();
                   }catch(NullPointerException npe){
                        done = true;
              numColumns-=1; //number of columns = 25
              converterIt();
              //Create new output file, if it exists delete it
              File myFile = new File("converted.xls"); 
              if(myFile.exists()){
                   myFile.delete();
              //Create new file output stream
              try {
                   fileOut = new FileOutputStream(myFile);
              } catch (IOException ioe) {}
              //write all conversion data to output file
              try{ 
                   wbout.write(fileOut);
                   fileOut.close();
              }catch (IOException ioe) {} 
         public static void converterIt(){
              boolean nextDone = false;
              boolean nextDone1 = false;
              for(int i=0; i<numColumns; i++){
                   clock =1;
                   rowIn = sheetIn.getRow(0);
                   cellIn = rowIn.getCell((short)i);
                   String getTopRow = cellIn.getStringCellValue();
                   sheetOut = wbout.createSheet(getTopRow+"_s"+i);
                   sheetOut.setColumnWidth((short)0, (short)(13 * 256));
                   sheetOut.setDefaultColumnWidth((short)25);
                   for(int j=0; j<=numRows; j++){
                        if(j==0){
                             rowIn = sheetIn.getRow(j);
                             cellIn = rowIn.getCell((short)i);
                             String temp2 = cellIn.getStringCellValue();
                             rowOut = sheetOut.createRow((short)j);
                             cellOut = rowOut.createCell((short)j);
                             cellOut.setCellValue(temp2);
                             cellOut = rowOut.createCell((short)(j+1));
                             cellOut.setCellValue("CLOCK");
                        if(j==1){
                             rowIn = sheetIn.getRow(j);
                             cellIn = rowIn.getCell((short)i);
                             double temp3 = cellIn.getNumericCellValue();
                             rowOut = sheetOut.createRow((short)j);
                             cellOut = rowOut.createCell((short)0);
                             cellOut.setCellValue(temp3);
                             cellOut = rowOut.createCell((short)1);
                             cellOut.setCellValue("");
                        nextDone=false;
                        nextDone1=false;
                        if(j>1){
                             rowIn = sheetIn.getRow(j);
                             try{
                                  cellIn = rowIn.getCell((short)i);
                             }catch(NullPointerException npe){
                                  rowIterator = "";
                                  nextDone=true;
                             if(!nextDone){
                                  try{
                                       rowIterator = cellIn.getStringCellValue();
                                       style = cellIn.getCellStyle();
                                  }catch(NullPointerException npe){}
                             if(j==2){
                                  rowOut = sheetOut.createRow((short)(clock+1));
                                  cellOut = rowOut.createCell((short)0);
                                  cellOut.setCellValue(rowIterator);
                                  cellOut = rowOut.createCell((short)1);
                                  cellOut.setCellValue(j-1);
                                  clock+=1;
                             }else{
                                  rowIn = sheetIn.getRow(j-1);
                                  try{
                                       cellIn = rowIn.getCell((short)i);
                                  }catch(NullPointerException npe){
                                       rowIterator1 = "";
                                       nextDone1=true;
                                  if(!nextDone){
                                       try{
                                            rowIterator1 = cellIn.getStringCellValue();
                                       }catch(NullPointerException npe){}
                             if(rowIterator1!=rowIterator && j>2){
                                  rowOut = sheetOut.createRow((short)clock+1);
                                  cellOut = rowOut.createCell((short)0);
                                  cellOut.setCellValue(rowIterator);
                                  //System.out.println(style);
                                  cellOut.setCellStyle(style);
                                  cellOut = rowOut.createCell((short)1);
                                  cellOut.setCellValue(j-1);
                                  clock+=1;
                        }//if
                   }//for
              }//for
         }//converterIt
    }//Converter1 CLASSEND

    I am not sure about the cell style as it looks like you are doing it right. For the null or blank cells it looks like you are only checking for null not "".

  • Problem with reflection in Generics

    I'm using the Prototype compiler for JSR-014 and I am having a big problem with reflection. In the simplest case
    class n<T> {
        void go() {
         this.getGenericType().getTypeParameters();
         this.getClass().getGenericInterfaces();
    }I get a "cannot resolve symbol" on both lines. A glance at the jar included with the prototype shows why: all the collection classes are there, and a lot of the java.lang types, but not java.lang.Class and none of the java.lang.reflection classes.
    So what gives? Is reflection not supported yet? (gaak!) Is there another jar I am supposed to download?
    Thanks

    Schapel is right.
    but also
    The signatures for fields and methods will include the generic types.
    If you really wanted to, this would work.
    get the Class's ClassLoader,
    work out the name of the Class's file, and get an inputStream to this resource (from the classloader). (This bit works because I use as a diagnostics tool to see if classes are loaded from my jar, or my patches directory - see below).
    Write some stuff to read the class file and parse out the generic signatures for the things you are interested in.
    I don't think this last part would fit into anyones definition of "fun", however the specs are all available, and it may turn out simpler than at first appearances.
    Here's the code I use to get the location of where a class is loaded from.
        static URL getLoadPath(Class theClass) {
            StringBuffer resourcename = new StringBuffer(theClass.getName());
            for(int i=0;i < resourcename.length(); i++) {
                if(resourcename.charAt(i) == '.') {
                    resourcename.setCharAt(i,'/');
            resourcename.append(".class");
            return theClass.getClassLoader().getResource(resourcename.toString());
        }if you use getResourceAsStream() in place of getResource() you will have the .class file as an inputStream which you can read and parse.
    Have Fun
    Bruce

  • Problem with Store.getFolder()

    I'm just writing a little program for my Blackberry Pearl that listens for email messages (in Java) Here is the relevant code:
    public void messagesAdded(FolderEvent e) {
            //Lets get the added message
            Store store = Session.waitForDefaultSession().getStore();
            Folder folder = Store.getFolder("INBOX");
            Message msgs[] = folder.getMessages();
            Message msg = msgs[0];
            //Now lets find out who sent the message
            Address from = msg.getFrom();
            //If the message is from [email protected] then make the phone ring
            if(from.toString().equals("[email protected]")){
               InputStream is = getClass().getResourceAsStream("sound.wav");
               Player p = Manager.createPlayer("http://216.7.189.162/globe/realtones/appliance/phonesring.wav");
                p.start();
            else{
               InputStream is = getClass().getResourceAsStream("sound.wav");
               Player p = Manager.createPlayer("http://216.7.189.162/globe/realtones/appliance/phonesring.wav");
                p.start();
        }So the problem is that when I use Store.getFolder, it says that I can
    t use a non-static method in a static context. But even when I create new classes in new class files that are obviously non-static it still doesn't let me do it. What am i doing wrong?
    Thanks in advance

    Is your program a MIDlet?
    Regards, Darryl

  • Problem with Image Loading

    Hi,
    I am using JWS to launch my application. Earlier I was using jdk1.5.0_12 version and everything was working fine. But, one of our machines didnt had jdk1.5.0_12 but had jdk1.5.0_19 version. So, JWS uses "Java Web Start 1.5.0_19" version.
    In my code, I am loading images at two different places. At first place I am loading my images using ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream baseInputStream = cl.getResourceAsStream(value);
              if(baseInputStream != null){
                  ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
                  byte[] buffer = new byte[1024];
                  int len;
                  while((len = baseInputStream.read(buffer)) >= 0)
                      out.write(buffer, 0, len);
                  baseInputStream.close();
                  out.close();
                  imageIcon = new ImageIcon(out.toByteArray());
              }This is working fine. But at the second place, I am setting the look and feel for my application using, SkinLookandFeel.loadDefaultThemePack() method. This method hangs permanently and my application fails to launch. When I debugged this method, I found the following:
    1. It goes to loadDefaultThemePack() method of SkinLookAndFeel class. (package: com.l2fprod.gui.plaf.skin)
    2. This in turn calls the loadThemePackDefinition((com.l2fprod.gui.plaf.skin.SkinLookAndFeel.class).getResource("/skinlf-themepack.xml")); of SkinLookAndFeel class.
    3. The XML file is loaded properly.
    4. In method loadThemePackDefinition(), the XML is parsed.
    5. This XML has a tag <icon name="InternalFrame.icon" value="icons/Window.gif" />.
    6. A URL is formed using URL iconURL = new URL(url, element.getProperty("VALUE"));7. This URL is also formed properly.
    8. Next, SkinUtils.loadImage(iconURL) is called.
    9. In this method, image is created using method: byte data[] = SkinLookAndFeel.getURLContent(url);
                img = Toolkit.getDefaultToolkit().createImage(data);10. The img variable created here has width and height = -1 with imagerep (consumer) as null, source (producer) as sun.awt.image.ByteAraryImageSource.
    11. Then, ImageUtils.transparent(img) method is called.
    12. In this method, toBufferedImage(image) method is clalled.
    13. in toBufferedImage(image) method, new image is created using image = (new ImageIcon(image)).getImage(); method.
    14. This new image created also has width and height = -1 with imagerep (consumer) as sun.awt.image.ImageRepresentation, source (producer) as ByteAraryImageSource.
    15. Now, new BufferedImage is created using BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 2);16. In the constructor of BufferedImage, createCompatibleWritableRaster(width, height) method is called on DirectColorModel. This method throws exception, since width and height are -1.
    Points to note are:
    1. This is working fine with jdk1.5.0_12 but not with jdk1.5.0_19. I tried this with latest java 1.5 version, jdk1.5.0_21. The problem is still there.
    2. When I tried with jdk1.5.0_12, instead of DirectColorModel instance, createCompatibleWritableRaster() method in point 16 above was called on IndexColorModel. I am not creating or initializing any color model, so, I dont know, when does the instance of DirectColorModel or IndexColorModel is used and whether it has any thing to do with my problem.
    Can any one provide any pointers, what could be the issue with jdk1.5.0_19.

    Have a look throughout the forum (and google), JWS retrieved url syntax changed in 5u16 (or 14 I can never remember).
    Otherwise keep waiting for some good samaritan, good luck with it, most people are sick tired of this topic.
    Bye.

  • Problem in reading a resource file form JAR

    Problem in finding a resource file from the jar.....
    I have my code in the following directory structure
    rootDir -
         libDir -
              XMLEntities.res
         modelDir -
              File1
              File2
              File3
    Step1 - I create a jar file with root as modelDir and with all its files.
    Step2 - I add XMLEntities.res also to the root of the jar
    If I run my application using
    java -classpath ;C:\aip_build\build_dm\rmi_server_files\dm.jar; model.data_model.ActivateDataManager
    My application which uses Xalan.jar (lyong under ext directory in jdk) does not find XMLEntiries.res.
    If I use my application as under without creating jar my application does find XMLEntites.res
    Can anyone tell me why the application can not find the XMLEntities.res inside jar?

    Sorry I missed one line............
    Problem in finding a resource file from the jar.....
    I have my code in the following directory structure
    rootDir -
    ----libDir -
    --------XMLEntities.res
    ----modelDir -
    --------File1
    --------File2
    --------File3
    Step1 - I create a jar file with root as modelDir and
    with all its files.
    Step2 - I add XMLEntities.res also to the root of the
    jar
    If I run my application using
    java -classpath
    ;C:\aip_build\build_dm\rmi_server_files\dm.jar;
    model.data_model.ActivateDataManager
    My application which uses Xalan.jar (lyong under ext
    directory in jdk) does not find XMLEntiries.res.
    If I use my application as under without creating jar
    my application does find XMLEntites.res
    java -classpath
    ;C:\aip_build\build_dm\rmi_server_files\;C:\aip_build\b
    ild_dm\rmi_server_files\lib
    model.data_model.ActivateDataManager
    Can anyone tell me why the application can not find
    the XMLEntities.res inside jar?try loading the resources as a InputStream
    something like :
    InputStream is = NameOfLoadingClass.class.getClassLoader().getResourceAsStream("XMLEntities.res");
    Hope this might help you in some way.

  • Problem with images in .jar file

    Hi all!
    I've got a severe problem when deploying an application via web start:
    the images withhin a deployed .jar file are not found.
    So far I've tried a number of things to get the images back, none of which are working.
    I've found different threads concerning this topic, e.g.:
    http://forum.java.sun.com/thread.jspa?threadID=396363
    http://forum.java.sun.com/thread.jspa?threadID=465795&messageID=2141351
    but sadly, they didn't help me out.
    Here is my code I'm using:
      private ImageIcon loadIconFromClassLoader(String tszRelPath)
        ImageIcon tIcon = null;
        cCat.info("tszRelPath = "+ tszRelPath);
        // this line simply leads to a crash of the whole application
        //tszRelPath = tszRelPath.replaceAll("\\", "/");
        if(!tszRelPath.startsWith("/"))
          tszRelPath = "/" + tszRelPath;
        cCat.info("modified tszRelPath = " + tszRelPath);
        URL tURL = ClassLoader.getSystemResource(tszRelPath);
        if(tURL == null)
          // this too crashes my application
          //tURL = PlainResourceProvider.class.getResource(tszRelPath);
        if(tURL != null)
          tIcon = new ImageIcon(tURL);
        return tIcon;
      }I've also tried
    PlainResourceProvider.class.getClassLoader().getResource()PlainResourceProvider is part of the .jar that involves the images.
    Of course all the .class files in the .jar file are easily accesible
    I would be so thankful, if just anyone could help me to solve this problem.
    I am going crazy.
    Thanks in advance, Christoph

    You should take care of the directory structure according to the package structure.
    I for example have this jar:
    C:\source\java\ebank2_util\smsunlock>unzip -l pro-ebank_sms_unlock.jar
    Archive:  pro-ebank_sms_unlock.jar
    Length    Date    Time    Name
          0  10-28-05  17:27   hu/
          0  10-28-05  17:27   hu/khb/
          0  10-28-05  18:17   hu/khb/smsunlock/
        256  11-07-05  16:33   hu/khb/smsunlock/DButils$MySQLException.class
       4229  11-07-05  16:33   hu/khb/smsunlock/DButils.class
       1700  11-07-05  16:33   hu/khb/smsunlock/GUI$1.class
       2318  11-07-05  16:33   hu/khb/smsunlock/GUI$2.class
        988  11-07-05  16:33   hu/khb/smsunlock/GUI$3.class
       1402  11-07-05  16:33   hu/khb/smsunlock/GUI$mywl.class
       5630  11-07-05  16:33   hu/khb/smsunlock/GUI.class
        818  11-07-05  16:33   hu/khb/smsunlock/LimitedLength_TextField.class
       2452  11-07-05  16:33   hu/khb/smsunlock/Main.class
        900  11-07-05  16:33   hu/khb/smsunlock/MyInputStream.class
          0  11-07-05  16:33   META-INF/
         98  10-27-05  15:53   META-INF/manifest.mf
         90  11-07-05  16:33   hu/khb/smsunlock/properties
      20881                    16 filesAnd the resource is loaded like this from hu.khb.smsu.Main:
    InputStream is = new MyInputStream( Main.class.getResourceAsStream( "properties" ) );

Maybe you are looking for

  • Replacing internal airport card

    This is my unit: Model Name: PowerBook G4 15" Model Identifier: PowerBook5,6 Processor Name: PowerPC G4 (1.2) Processor Speed: 1.5 GHz Number Of CPUs: 1 L2 Cache (per CPU): 512 KB Memory: 2 GB Bus Speed: 167 MHz Boot ROM Version: 4.9.1f3 I was on a t

  • Synchronization with different PC's.what is happening & old material erases

    Hello, I just bought my IPOD TOUCH. but,,,, Iam using three different pc's to download mucic and podcasts and everything. one at home, two in work. That means i have created three different libraries. Today for the first time, I tried to downlaoad to

  • BBM Group on Playbook

    Hi BB, Serious question, when I am able to get the BBM Group on my playbook? Is there any update for this feature? Or it's already exists and I can download the update. And also for whatsapp, is there any group chat feature for Playbook like in BB ha

  • How to rectify downloaded books with efile protected on them

    After trying to download a library book, it went to my ebook reader okay but cannot be opened as it says efile protected, lso all books |I have previously downloaded are now unable to be opened for the same reason, how do I rectify this?

  • Increse this performance in the secect querey

    Hi every one i am not able to solve can any on help to slove this query ithere is performance issue with this query select fmblnr fbktxt pmwskz fmjahr  into corresponding fields of table it_final1 from mkpf as f inner join mseg as p on fmblnr = pmbln