Problem with Class.getResource()

I am trying to load a jar file dynamicaly like,
ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader m_ClassLoader = new URLClassLoader(new URL[] {new URL(sV1JarPath)}, prevClassLoader);
But after doing this if I try to load a resource from the "prevClassLoader " like,
MyClass.class.getResource("path"); where MyClass is loaded by prevClassLoader, it is not working. It fails to load the resource.
Can anyone help me correct this issue?
Thanks
Unni

try "/path".I am giving it like
MyClass.class.getResource("images/" + name); where there is an images packages in side the package where MyClass resides.
But here the problem is as MyClass is in the prevClassLoader and it is not able to find it when we call Class.getResource()

Similar Messages

  • Different result with class.getResource/ getClassLoader ...

    There is something about resource loading I don't understand. According to the api the method getResource() calls the ClassLoader for loading the given resource. But the following example shows a difference:
    package testPackage;
    public class Test
        public static void main(String[] args)
            Test t = new Test();
            System.out.println(Test.class.getResource("testPackage/test.class")); 
    System.out.println(Test.class.getClassLoader().getResource("testPackage/test.class"));
            System.out.println(t.getClass().getResource("testPackage/test.class"));
    System.out.println(t.getClass().getClassLoader().getResource("testPackage/test.class"));
    }The resulting output is:
    null
    file:/C:/.../bin/testPackage/test.class
    null
    file:/C:/.../bin/testPackage/test.classHow can this difference be explained?

    There is something about resource loading I don't
    understand. According to the api the method
    getResource() calls the ClassLoader for loading the
    given resource. As noted, the API also explains the algorithm used to get an absolute resource name from the initial resource name, before delegating to the classloader.
    Basically, a package name prefix is added if the name is not absolute (i.e doesn't start with a leading slash).

  • Problem with Class and Classpath

    Hello ME Windows Users, now before you place a wry smile on your face, I have a problem with path and classpath. Stop it, I can see you smiling!
    By visiting the the last 10 pages of the forum and reading Sun installation notes, some tooldocs and by given some answers by some nice people, I have become an expert in turning off my computer, about 10 times/hr. I still am trying to make my first cup of java.
    With the ME computer,
    I'm unable to right click on the desktop and go to properties, advanced,
    I'm unable to go go start, run, sysedit,
    I'm unable to change the ms-dos window of autoexec.bat, it just shuts down.
    Now before you tell me, I should of bought a different computer, the only place I can find to modify the path and classpath is in the environment which is in system configuration under tools. Here I have placed numerous configurations, like
    C:\java>set path=%path%;c:\j2sdk1.4.2\bin
    C:\java>set classpath=%classpath%;.;
    ;java_dir\bin where ;java_bin is c:\j2sdk1.4.2
    .; java_dir\bin; %path% where ;java_bin is c:\j2sdk1.4.2 and the list goes on.
    But, I know you are still smiling, the % signs comes up in a dialog box, saying too many, and will not convert the text to the environment to be saved when I close down for the tenth time in the last hour.
    Can someone help me before I make a real cup of coffee and accidentally drop it on the ME box.
    Have a laugh on me Mik.

    C:\java>set path=%path%;c:\j2sdk1.4.2\binGood
    But it is no good because it has to many % and a dialog box appears, saying you have too many parameters.
    Are you saying I have to shutdown again to answer your ?
    From the HELP menu-
    To confirm startup commands line by line
    Click Start, and then click Shut down.
    Click Restart, click OK, and then press and hold the CTRL key until the Windows Startup Menu appears.
    Enter the number for Step-by-step confirmation, and then press ENTER.
    For each command you want to run, press Y.
    If the command runs successfully, you are prompted with the next command.
    If the command does not run successfully, you receive an error message.
    To skip a command, press N.
    Mik

  • [APPLET][Heritage] Problem with classes

    Hi, I'm developping a simple JAVA Applet and I have a problem
    I have a class called LUIweb which is the main class. Here is a part of it.
    public class LUIweb extends JApplet implements Runnable {
    public void run() {
    DisplayMessage("JAVA rocks");
    public void DisplayMessage(String message){
    jtextArea.append(message);
    middlePanel.removeAll();
    middlePanel.add(textScrollPane, BorderLayout.CENTER);
    middlePanel.validate();
    middlePanel.repaint();
    It displays the message "JAVA rocks" in my JTextArea. But when another class from the same package calls DisplayMessage, nothing is displayed in my JTextArea
    public class Data_net extends LUIweb{
    public void Test(){
    DisplayMessage("NON");
    Have you got any idea to fix that?
    Thank you for you help

    OK,
    You are using a separate thread to update the gui. As swing is not multithread safe, this is not good. Anytime you want to change the gui, you must do it on the gui thread. This means without extra help, you should only change the gui from within a Listener, such as a MouseListener, KeyListener, etc, etc.
    In your case, you are updating the not from the gui thread (not from a Listener), and so you must ask the gui thread to do the work for you when it has time.
    This means you need to use SwingUtilities.invokeLater or SwingUtilities.invokeAndWait.
    Since the sequencing is important to you in your code, you should probably use invokeAndWait, such as
    public void run()
              SwingUtilities.invokeAndWait( new Runnable()
                     public void run() { DisplayMessage(Language.CONNECT_DB); }
              Data_net Donnee_net=new Data_net();          
              SwingUtilities.invokeAndWait( new Runnable()
                     public void run() { DisplayMessage("Connecting to "+Donnee_net.GetHost()+
                                                       " with user "+Donnee_net.GetUser()+"...\n");
              Donnee_net.Test();   

  • Problems with classes referencing each other...

    I've got a problem....i have a program with two classes, and each class needs access to methods stored in the other class.
    I've tried to create a reference (Classname name=new Classname();), but upon execution, i get a Exception in thread "main" java.lang.StackOverflowError, and a long list of locations, all pointing to the references i created at the top of each class.
    What's wrong, and how do I fix this?

    You have infinite recursion. A method or constructor is calling itself, or is calling another method or constructor that eventually ends up calling the first one.
    If you can't find it, post code. Use [code] and [/code] tags, which you can get with the code button, to make the code readable.

  • A stange problem with class Random

    I am doing with a simple test of class random as follow:
    public class Test{
      private static rand=new Random();
      public static void main(String args[]){
          int i=rand.nextInt(10);
          System.out.println(i);
    }When I compile the program using javac,error occurs.It says
    Wrong number of arguments in method
    private int i=rand.nextInt(10)
    ^
    If I remove the arg "10" ,it works fine.So I have to rewrite it as below:
      private int i=rand.nextInt(10) % 10;I am puzzled now.Why can't I use the int nextInt(int n) method of class Random?

    Thanks for your advice.
    I have tried as what you have said ,and the codes seem like these:
    import java.util.*;
    public class test {
         private static Random rand = new Random();
         public static void main(String args[]){
              int i=rand.nextInt(10);
              System.out.println(i);
    }and the file name is test.java of course.
    But it cause the same error.
    And when I compile the same code on another machine ,it wors fine!
    (all the two machines are installed with win2k server and j2sdk1.4.1_01).
    Why there exists problems and difference?
    Did I have to set something else of the system?

  • Problems with class CL_GUI_FRONTEND_SERVICES

    Hi.
    I already searched for a solution in the forum, but haven't found anything yet.
    I use the method to check if a directory exists and the one to list the files. The user can specify the directory on the Appl.-Server via SELECTION-SCREEN. First the code:
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST
      EXPORTING
        DIRECTORY            = l_unixpath
      RECEIVING
        RESULT               = l_count_unixdir
      EXCEPTIONS
        CNTL_ERROR           = 1
        ERROR_NO_GUI         = 2
        WRONG_PARAMETER      = 3
        NOT_SUPPORTED_BY_GUI = 4
        others               = 5.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
      EXPORTING
        DIRECTORY            = l_unixpath
      CHANGING
        file_table           = l_itab_unixdir
        count                = helpvar
      EXCEPTIONS
        CNTL_ERROR           = 1
        ERROR_NO_GUI         = 2
        WRONG_PARAMETER      = 3
        NOT_SUPPORTED_BY_GUI = 4
        others               = 5.
    IF l_count_unixdir = 'X'.
      WRITE: / 'Directory Exists'.
      READ TABLE l_itab_unixdir INDEX 1 INTO l_unixdir.
      WRITE:/ helpvar.
      WRITE:/ l_unixdir.
      WRITE
    ELSE.
      WRITE:/ 'Directory not found'.
    ENDIF.
    Now my problem:
    l_unixpath is '/', the result is: Directory exists, but helpvar is 0, l_itab_unixdir is empty;
    l_unixpath is '/usr/sap/', the result is: Directory not found <b>(but the directory exists!)</b>;
    l_unixpath is 'c:/', the result is: Directory exists, helpvar is 47, l_unixdir is "Documents and Settings".
    Why it's working with the Windows-Path but not with Unix? Thanks for your answers.

    Becose that class is for presentation server. You can't use it with application server.
    Try FM F4_DXFILENAME_TOPRECURSION, may be helps.
    Regards.

  • Problems with class MdmDimension

    Hello, I've created some dimensions and cubes using cwm2 packages, in Oracle 9i.
    Now I'm trying to use these objects in a j2ee aplication using olap api. My problem is: when I try to display the properties (display_name, plural_description, description, ...) of my dimensions (using MdmDimension class), the result is not the same of the same properties using ALL_OLAP2_DIMENSIONS view.
    For example, the PR01 dimension has the next descriptions (using ALL_OLAP2_DIMENSIONS view):
    plural_name: 'Prueba01 plural'
    display_name: 'Prueba01 display'
    short_description: "Prueba01 short'
    description: 'Prueba01 description'.
    And now, using the methods on MdmDimension class, I've got the next results:
    getPluralDescription() --> 'Prueba01 plural' OK
    getShortDescription() --> 'Prueba01 display' ????
    getShortPluralDescription() --> 'Prueba01 plural' OK
    getDescription() --> 'Prueba 01 short' ????
    I need to display the description ('Prueba01 valen'), but I haven't found the way.
    What is failing ? My database version is 9.2.0.6, and I'm using MdmDimension from package oracle.express.mdm. Thanks a lot by your help.

    Hi Edmund,
    I'm having the same problem in the same upgrade scenario. Did you find a solution for this big issue?
    Thanks.
    Patricio.

  • Problems with Classes

    Hi everyone.
    I am using a scroller class from kirupa, however i am having
    a small problem. Everything works fine if i place it all on the
    main time line. however when i want to package all the mc's used
    for the scroller into a mc of it own the scroller will not update
    for the new content. I am losing some hair trying to tackle this
    one on my own and would love it if someone could help.
    Here are the files:
    EDITED: i have just added both the version of the scroller in
    a container...and one that is not. The one that is not work
    perfectly, the one that is in the container has the flaw that when
    the new content is loaded in the scroll bar does not hide or change
    height, it keeps the property of the initial mc loaded.
    Hope that makes sense.
    Zipped
    Files
    Thanks for all for taking time for this.
    Very much appreciated,
    Martha Stewart

    Think it works (almost) properly now. This is the code for
    the buttons (change the mc to attach...)
    on(release){
    Scroller.contentMain.unloadMovie;
    Scroller.contentMain.attachMovie("historytxt","newcontent",1)
    // Line of importance
    setTimeout(Scroller.myscrollbar, "setScrollProps", 50);
    Scroller.myscrollbar.backToTop();
    Make one correction in the class:
    public function backToTop():Void
    dragger._y = top;
    content._y = 0; // instead of 'top'
    updateContentPos();
    Now that last correction disables the easing effect when
    clicking on a new topic, but there's something wrong in the class
    and the 'new' values are not correct. I'll try to figure it
    out.

  • Event Dispatch Problem With Classes

    I have a custom Timer class that pops up an inactivity alert
    after 3 minutes. The user can then choose 'yes' if they are still
    editing a record or 'no' if they are done. If they do not respond
    within 2 minutes of the alert it assumes 'no'.
    A 'yes' refreshes the timer and closes the alert.
    A 'no' kicks them out of the edit state in the component that
    the timer is called from.
    The logic of the timer is working fine but it doesn't seem to
    be sending the event to the component that called it so clicking
    'no' (or remaining inactive) does nothing. I feel like I'm missing
    something really simple or just misunderstanding the
    eventDispatcher function. Advice please??
    Code From LockTimer class:
    public class LockTimer extends Sprite
    private var threeMinuteTimer:Timer;
    private var twoMinuteTimer:Timer;
    public function LockTimer()
    // creates a new threeMinute Timer
    threeMinuteTimer = new Timer(1000, 180);
    twoMinuteTimer = new Timer(1000, 120);
    // designates listeners for the interval and completion
    events
    threeMinuteTimer.addEventListener(TimerEvent.TIMER, onTick);
    threeMinuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
    onTimerComplete);
    twoMinuteTimer.addEventListener(TimerEvent.TIMER, onTick);
    twoMinuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
    onTimerCompleteB);
    // starts the timer ticking
    threeMinuteTimer.start();
    public function refresh():void{
    restart(threeMinuteTimer);
    twoMinuteTimer.reset();
    private function onTick(evt:TimerEvent):void{}
    private function onTimerComplete(evt:TimerEvent):void{
    //trace("first timer");
    Alert.show('You have been inactive for several minutes. Are
    you still editing this record?', 'Inactivity Alert',
    Alert.YES|Alert.NO, null, alertListener,null, Alert.YES);
    twoMinuteTimer.start();
    private function onTimerCompleteB(evt:TimerEvent):void{
    //trace('second timer');
    //Alert.show('TIME UP', 'Inactivity Alert', Alert.OK);
    dispatchEvent(new Event("timeUp",true));
    private function restart(tim:Timer):void{
    tim.reset();
    tim.start();
    private function alertListener(eventObj:CloseEvent):void{
    // Check to see if the YES button was pressed.
    if (eventObj.detail==Alert.YES) {
    refresh();
    }else{
    //exit edit mode
    //Alert.show('TIME UP', 'Inactivity Alert', Alert.OK);
    dispatchEvent(new Event("timeUp",true));
    Code From Component:
    private var theTimer:LockTimer;
    private function initializeHandler(event:Event):void{
    addEventListener("timeUp",timeUpHandler);
    private function timeUpHandler(event:Event):void{
    Alert.show('TIME UP', 'Inactivity Alert', Alert.OK);
    //editDone();
    }

    so here is what i had to do to make this work:
    1. I had to attach the listener to theTimer rather than the
    component
    2. I had to initiate the LockTimer constructor outside of the
    function
    3. I had to call the handler initialization function from the
    component MXML
    below is the revised code (with excess cut out)
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HDividedBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="780" height="515" liveDragging="true"
    creationComplete="initializeHandler()">
    <mx:Script>
    <![CDATA[
    import mx.controls.Text;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.controls.Alert;
    import classes.LockTimer;
    public static const millisecondsPerMinute:int = 1000 * 60;
    public static const millisecondsPerHour:int = 1000 * 60 *
    60;
    public static const millisecondsPerDay:int = 1000 * 60 * 60
    * 24;
    //IMPORTANT!!!////////////////
    private var theTimer:LockTimer=new LockTimer();
    private function initializeHandler():void{
    theTimer.addEventListener("timeUp",timeUpHandler);
    private function timeUpHandler(event:Event):void{
    editDone();
    private function refreshLock(theLock:int):void{
    var theTime:Date=new Date();
    if(theLock==1){
    theTimer.refresh();
    theTime.setTime(theTime.getTime() +
    (millisecondsPerMinute*5));
    }else if(theLock==0){
    theTime.setTime(theTime.getTime());
    }else{
    return;
    form1.request.firmlockedTime=String(theTime.valueOf());
    form1.request.firmisLocked=String(theLock);
    private function editIt():void{
    //see if it's being edited
    if(checkLock()){
    //if its being edited send a message
    Alert.show('This record is currently being edited by another
    user. Please try again later.', 'Record Locked',
    mx.controls.Alert.OK);
    }else{
    theTimer.startMe();
    refreshLock(1);
    form1.send();
    currentState="AdminEdit";
    private function editDone():void{
    refreshLock(0);
    form1.send();
    currentState="Admin";
    ]]>
    </mx:Script>
    </mx:HDividedBox>

  • Problem with classes generated with .classgen

    When I run the sample app from the "Using XML in Oracle Database Applications, Part 2" that generates classes, the syntax is:
    java SampleMain -root MYMAIN myfile.dtd
    All the elements in myfile.dtd get a class built for them, but they also reference MYMAIN as a class. That is, things like:
    public MYMAIN getDocument()
    return (MYMAIN)super.getCGDocument();
    I would have expected that classgen would have made a class called MYMAIN, but it did not. I'm very confused. Please help.
    Thanks,
    -Peter
    null

    Check if you have MYMAIN in your
    DTD file:
    <!ELEMENT MYMAIN ......

  • Problem with class font

    I have been execute a tool, but she didn�t work properly.
    The message erro is unknown option "-class"font "-dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*"

    Hello dmytro,
    see the heading (translated from my German ID) >>> input method options, check this box and use the integrated input for non-Latin text. This ensures that languages such as Cyrillic, etc that are not based on the Latin alphabet, can be used in InDesign anyway. And note: The operating system of your computer must support this language systems. Otherwise it does not work.
    Another possibilty would be that you use WORD (or similar) to build your text and put it (copy and paste) into your ID.
    On the other hand you could use fonts like Myriad Pro oder Minion Pro and integrate them into your WIN or MAC, so that ID can find them.
    Adobe can provide you Russian fonts too, please have a look at
    http://blog.typekit.com/2013/06/04/coming-to-your-desktop-futura-pt-adonis-from-paratype/
    http://blog.typekit.com/2014/07/09/source-sans-v2/
    Hans-Günter

  • Problem with Class Diagram

    hi all,
    Can any one tell me how to represent in the class diagram, the relation b/w classe if the code is some thi ng like this
    class A
    B obj = new B();
    class B
    B()
    plz help me

    UML:
    http://bdn.borland.com/article/0,1410,31863,00.html
    http://www.smartdraw.com/tutorials/software-uml/uml.htm

  • Problems with Class.forName("com.sun.sql.jdbc.db2.DB2Driver")

    In sun java studio enterprise 8
    I'm able to connect to my local DB2 sample database by creating a database schema.
    But when I try to execute a java class (main) using
    Class.forName("com.sun.sql.jdbc.db2.DB2Driver"). It returns a not found condition.
    what am I doing wrong? do I have to point the classpath to some directory?

    try to add jar containing driver to
    Your project -> Properties -> Libraries -> Run list.

  • Problem with Class Category log4J

    Can I set a different Priority in my
    object Category if I am not inside a method ?
    If I write this:
    Category cat = null;
    cat.info("Hello I am cat");
    and before that I would like to set for cat object
    a different priority but without to do that inside a method.
    For example when I write Category cat;

    You have to do this in the Log4j configuration file (log4j.properties). Add a line like:
    log4j.categoryname=INFO
    Read the documentation of Log4J if you don't know how to use the log4j.properties file.
    Jesper

Maybe you are looking for

  • Can I send files from iCloud to iTunes?

    Itunes had a corrupted file so I had to unisntall and reinstall so all my files were gone from iTunes. Last time I backed up my phone I used iCloud. is there a way to send the info from iCloud to iTunes so I can sync my phone with itunes without losi

  • Very slow Word file import on RoboHelp HTML 8

    Hello, I am currently using RoboHelp HTML 8.0.2 on Vista 64-bit and when I import Word files (both .doc and .docx) it takes a really long time to complete (10-15 minutes for a 200pg/50topic/10MB Word file). Is this normal? At the end of the process i

  • How to give query in lookup type udf in OIM 11g

    Hi, In OIM 9.x, we were able to provide query in lookup type field in users UDF to fetch data from DB and display it in lookup table. Where as in OIM 11g, I cant find that option. We need to provide user id in lookuptype field based on some query. Pl

  • Help port mapping for lorex security system

    i need to find out how to do my port mappping, not sure what to put in the fields . trying to set up for remote viewing. i have ddns set up, but need port mapping

  • IDVD Crashes when opening an exisitng IDVD project

    When I try and open one of my iDVD projects I get this message in the console.log: 2008-05-20 21:21:36.971 iDVD[239] NSExceptionHandler has recorded the following exception: NSInvalidArgumentException -- * -[NSCFDictionary setObject:forKey:]: attempt