No such class at run--time?

Hi there.
I'm trying locate the following constructor at run=time:
package cliquespace.core.agentdevice.cliquespace.agent.device.spine;
final public class AgentDeviceActiveAffiliation extends DeviceActiveAffiliation<AgentDeviceActiveAffiliationPrecis,AgentDeviceMediaProfile,
AgentDeviceConnection,AgentDeviceActiveAffiliation>{
    public AgentDeviceActiveAffiliation(SourceCliqueSpace sourceCliqueSpace,LimitingConstraint[]limitingConstraints,
        AgentDeviceActiveAffiliationPrecis precis)throws CliqueSpaceException{
        super(sourceCliqueSpace,limitingConstraints,precis);
    }Note that DeviceActiveAffiliation extends SourceActiveAffiliation.
I use the following code to do this:
214    public SourceCliqueSpaceElement createElementFromPrecis(SourceCliqueSpace cliqueSpace,SourceCliqueSpaceElementPrecis precis)
215     throws CliqueSpaceException{
216        /**
217         * Get the Element's class.
218         */
219        Class cl=null;
220        try{
221            cl=Class.forName(precis.getElementCanonicaName());
222        }catch(ClassNotFoundException cnfe){
223            ReceiveElementGivenCanonicalTypeHasNoSourceCliqueSpaceElement x=
224             new ReceiveElementGivenCanonicalTypeHasNoSourceCliqueSpaceElement(precis.getIdentifier(),precis.getElementCanonicaName());
225            x.initCause(cnfe);
226            throw x;
227        }
228
229        /**
230         * Get the class's precis constructor.
231         */
232        Class[]paa=new Class[3];
233        if(precis.getCliqueSpaceType().equals(AgentCollaborationCliqueSpace.class.getSimpleName())){
234            paa[0]=AgentCollaborationCliqueSpace.class;
235        }else if(precis.getCliqueSpaceType().equals(AgentDeviceCliqueSpace.class.getSimpleName())){
236            paa[0]=AgentDeviceCliqueSpace.class;
237        }else{
238            throw new CreateElementFromPrecisCliqueSpaceTypeIsUnknown(this.getName(),precis.getCliqueSpaceName(),precis.getCliqueSpaceType());
239        }
240        paa[1]=LimitingConstraint[].class;
241        paa[2]=precis.getClass();
242        Constructor co=null;
243        try{
244            co=cl.getConstructor(paa);
245        }catch(NoSuchMethodException nsme){
246            ReceiveElementNoPrecisConstructorExistsForSourceCliqueSpaceElement x=
247             new ReceiveElementNoPrecisConstructorExistsForSourceCliqueSpaceElement(precis.getIdentifier(),precis.getElementCanonicaName());
248            x.initCause(nsme);
249            throw x;
250        }
276    }[/code.
However, when the code runs, I get the following exception:cliquespace.core.exception.agentdevice.agentdevice.ReceiveElementNoPrecisConstructorExistsForSourceCliqueSpaceElement: An Element identified by [9DNCEJ0AVQVJLJEHP00EKTKKJWMXB77U2C9XCZAQ] of type [cliquespace.core.agentdevice.cliquespace.agent.device.spine.AgentDeviceActiveAffiliation] cannot be constructed from a received precis because the given class has no precis constructor.
Caused by: java.lang.NoSuchMethodException: cliquespace.core.agentdevice.cliquespace.agent.device.spine.AgentDeviceActiveAffiliation.<init>(cliquespace.core.agentdevice.cliquespace.AgentCollaborationCliqueSpace, [Lcliquespace.core.cliquespace.constraint.LimitingConstraint;, cliquespace.core.agentdevice.cliquespace.agent.device.spine.activeaffiliation.AgentDeviceActiveAffiliationPrecis)
        at java.lang.Class.getConstructor0(Class.java:2723)
        at java.lang.Class.getConstructor(Class.java:1674)
        at cliquespace.core.agentdevice.AgentDevice.createElementFromPrecis(AgentDevice.java:244)
        at cliquespace.core.agentdevice.AgentDevice.receiveElement(AgentDevice.java:346)
        at cliquespace.core.agentdevice.AgentDevice.receiveElement(AgentDevice.java:64)
...[/code]
Note, AgentCollaborationCliqueSpace also extends SourceCliqueSpace. So, specifying either AgentCollaborationCliqueSpace or AgentDeviceCliqueSpace should yield the given constructor.
As far as I can determine, the other parameters line up.
It's got me stumped. Your advice, suggestions and/or, help would be appreciated.
Thanks,
Owen.

One needs to use the class declared in the parameter, even, as SourceCiqueSpace is in this case, if the class is abstract.

Similar Messages

  • How to invoke a class at run-time for primitive data types?

    Hi,
    I am trying to invoke classes at run-time.
    I am using Class.forName("className") for that where the "className" is also obtained at run-time .
    The problem I am getting is when the "className" is "int" or "char" etc. the call to Class.forName("int") etc. fails giving ClassNotFound error. It works fine for "className" is "java.lang.String" or "java.lang.Integer" etc.
    How can I correct this?
    thanks in advance-
    kg

    Hi,
    Thanks all for the valuable inputs.
    I have created a hashtable of primitive data types in the form of "int" as key and "Integer.TYPE" as the object in that element of the hashtable.
    Now there is another problem I am facing and that is of 'Casting at run-time'.
    Problem is there when the Database type is 'NUMBER' which returns me a "java.lang.BigDecimal" when I do a ResultSet.getObject("XXX") for that whereas the method in the javabean expects an "int" type.
    This causes "java.lang.IllegalArgumentException: argument type mismatch"
    So I want to cast it at runtime. How can I do it?
    Here is the code I am trying (which generates the above exception)
    public static void setBeanField(Class pCls,Object pObj,String pMethodName ,Object pColumnValue,Class
    pColumnTypeClass){
    try{
    if(pColumnValue!=null){
    Class[] paramTypes = new Class[]{pColumnTypeClass};
    Object[] args = new Object[]{pColumnValue};
    Method meth = pCls.getMethod(pMethodName,paramTypes);
    meth.invoke(pObj,args);
    }catch(Exception e){
    System.out.println("Exception in TestInrospection.setBeanField " + e);
    thanks in advance-
    kg

  • How to instantiate classes at run time with constructors having arguments?

    I have to instantiate some classes in the run-time because they are plugins. The name of the plugin (pluginClassName) comes from a configuration file.
    Currently I am doing this to achieve it:-
    UIPlugin plugin = (UIPlugin)Class.forName(pluginClassName).newInstance();However, there is a disadvantage. I can not pass arguments to the constructor of the plugin.
    public class RainyTheme extends UIPlugin {
      public RainyTheme() {
       // bla bla
      public RainyTheme(int x, int y , int width, int height) {
       // set co-ordinates
       // bla bla
      // bla bla bla bla
    }Now if I want to instantiate this plugin at runtime and at the same time I want to pass the 4 arguments as shown in the second constructor, how can I achieve this?

    I have no experience with JME and the limitations of its API, but looking at the API docs ( http://java.sun.com/javame/reference/apis.jsp ) it seems that there are two main versions, CLDC and CDC, of which CLDC is more limited in its API.
    The Class class does not contain the methods getConstructor(Object[]) or getConstructors() in this version ( http://java.sun.com/javame/reference/apis/jsr139/java/lang/Class.html ), so it seems that if you are using CLDC then there is no way to reflectively call a constructor with parameters. You'd have to find another way to do what you want, such as use the noarg constructor then initialise the instance after construction.

  • Print methods of a class at run-time

    Suppose I have a class. At run-time I get an object of that class. I want to print methods defined in that object using System.out.println(). How can I do that?
    Thanks

    Take a look at Object.getClass(). It returns a Class object. Then look at the methods within the Class class that you can invoke. Some of them return arrays of Method objects, for instance.
    Learn to read the API and experiment with the available methods you already have (such as getClass(), available for every object).
    http://java.sun.com/j2se/1.4.2/docs/api/index.html

  • LoadClass    (error loading a class which extends other class  at run-time)

    Hey!
    I'm using the Reflection API
    I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
    CustomClassLoader loader = new CustomClassLoader();
    Class classRef = loader.loadClass("SubClass");
    class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.
    This is what 'findClass(String className)' returns:
    defineClass (className,byteArray,0,byteArray.length);
    'byteArray' is of type byte[] and has the contents of subdir/SubClass.
    the problem:
    The program runs fine if SubClass does not extend any class.
    If however, SubClass extends another class, the program throws a NoClassDefFoundError. How is it conceptually different?
    Help appreciated in Advance..
    Thanks!

    Because i'm a newbie to the Reflection thing, i'm notI don't see reflection anywhere. All I see is class loading.
    sure what role does the superclass play when i'm
    trying to load the derived class and how to get away
    with the errorWell... hint: all the superclass's stuff is not copied into the subclass.
    I am quite sure it fails to load the superclass because of classpath issues.

  • How to Load Classes in run time - Urgent

    Hi All,
    How to Load a class file from a .jar file in JDK1.1 with out using URLClassLoader. I have tried to extract the .jar file by file input stream and zipEntry classes and defineClass using the bytes i got from the stream , but the class loader fails to take the classes that are already loaded in the system.
    The customClassLoader that i created was not able to assign an object to the another reference variable that already in the JVM.Please i want to know how to assign or communicate between the objects of CustomclassLoader and SystemClassLoader?
    Please help me in this regard.
    Thanks in advance,

    Hi,
    The above code works in the straight way if the class is available in the classpath.
    I need to load a class by using custom class loader that i extends from classloader base class .
    I have to read a class file from a .jar file (in server) and load it in run time.Here i am able to read the bytes from the .jar file of the specified class file, but the class that i read extends some other class that is already loaded when i tried to create newInstance of the class i get Exceptions. Here the custom classLoader cannot find the loaded existing class in the JVM.can i get a solution for this situation

  • Can't find class at run time

    i have equation.dtx , equation.class and equationImp.class in my web project at respective places.
    I am trying to use equation.class programatically in one of my ejb which is in another ejb project. at compile time the ejb gets the equation.class and build's succesfully but when i run the program it's give me error
    "java.lang.NoClassDefFoundError:" for equation.class.
    Can anybody tell me what is the root cause of this problem and how can i fix it.
    all opinions are welcome
    Thanks in advance

    I am also getting the same <b>NoClassDefFoundError</b>.I ensured the ejb jar is in classpath. I set that from Weblogic Builder.Can anyone help me??
    Thx in advance.

  • How to Convert Externalizable objec to Serializable at Run Time

    Urgent Help needed ...
    Original Problem
    We are using Externalizable object through the system .We keep track of versioning with field in each object ...
    This version is common software version...
    We change that version every two or three week ...
    suppose for
    My software Version is 2
    and suppose if someone add a new field to any object we put a checking in readExternal to not read that field is the version is less than 2
    Now the problem is say
    1)We make a version 2 on June 10
    2)Some one save a object on June 11
    3)Some one add a new field in any object and put the checking of Version 2
    4)Now object saved in step 2 cannot be read once step 3 is performed...
    How do we solve this issue ?
    We do not intend to add the class Version in each class at this stage. ...
    Issue 2
    Other issue related to issue 1 itself
    We plan to convern the object to xml using some technology of Xstream
    Now issue 1 can be solved atlease if my all the object were of type Serializable and NOT EXTERNALIZABLE
    So my Second Question is is there a way to convert a Externalizable object to Serialiable object just for my purpose when i m converting to xml and vice versa .....
    Basicallly I want a way to remove that EXTERNALIZABLE Interface from class at run time WITHOUT CHANGING ANY CLASS SOURCE CODE ...../
    Guy Your help is very appreiciated to solve this two issue
    Message was edited by:
    palanmahesh

    It seem i have not properly explained to you guys my
    problem
    I cannot change the code of existing object which are
    Externalizable..
    Nor can i solve the versioning issue That block of
    source code i cannot touch
    all i want is somehow convert the object so that they
    are not instance of Externalizable Well it seems pretty hopeless then doesn't it.
    My advice? Give up. You seem pretty lost and when people respond by basically saying they can't solve the problem in any reasonable way then it's pretty much a lost cause.
    Good luck with your hopeless task. I see nothing but upset in your future.

  • Class to jar communication at run time

    Hi,
    I am developing a application using jdk 1.4 and have following query:
    I have an application that displays some information in various languages (according to the language selected), i.e english, french, german etc. Say I select english, the application will display "Hello World" in English language and so on for other languages..
    So my app is divided into three parts:
    1) Core application : displaying information
    2) XML file: Containing list of languages in XML format. This XML File can be updated for adding new languages. The format of XML file is somewhat as
    <LANGUAGE_NAME>___</LANGUAGE_NAME>
    <CLASS_LANG>____</CLASS_LANG>
    3) A seprate JAR file :Having set of classes corresponding to each language. The JAR file should be such that we can add classes for new languages added.
    The Workflow of app is as follows:
    When ever we run the application, the application reads the list of languages from the XML file and populats the list in a drop-down list box. Now, upon clicking a "GO" button, the application checks the language selected and calls the JAR will. It sends the class name corresponding to the language selected. And the class should return the information back to the application.
    Now, this process should be dynamic, i.e user can update XML with new language and update the JAR file with new class name.
    And upon just re-running the application, the application should be able to use features of new language.
    Consider that we have already shipped the application. All we have to do is to send updated JAR file to the user. and ask him to update the XML file for new language. i.e no changes to be done at application. And application should communicate with update JAR files at the end user.
    Now I have following queries:
    1) Is the above process possible? If yes, then
    2) How to communicate my application with the new class files in JAR file. i.e how to communicate my class with the UPDATED class in JAR file. Any prototype code to achieve this functionality would be of great help. Remember all this need to happen at run time.
    I hope my question is clear. Feel free to ask any queries.
    Thanks,
    rdh

    Java has a mechanism to cope with this - though it is not XML-based:
    java.util.ResourceBundle
    I would store the required resource (a property file or the XML or a jar) separately.

  • Run time error while using Class gcl_error

    Hi All,
    I am getting run time error while using class gcl_error
                                          type REF to zsreport_error_handling:
    '' Attempt to access a component using 'NULL' object reference (points to nothing).
    An object reference must point to an object ( an instance of a class) before you can use it to access components ( variable : ''GCL_ERROR'').
    Either the reference point has not yet been set or it has been reset to 'NULL' by a clear statement."
    Can you please suggest any solution for this ?
    Thanks in advance.

    Dear All
    Its Resolved Thanks For your Valuable time Support
    INCLUDE LV03VFB4 inside below code trigger error.
    PERFORM VVBBD_AUFBAUEN USING WA_AVBBD
                                        WA_AVBBD-APOMOBILE
                                        DA_SUBRC
                                        DA_UPDKZ
                                        DA_VVBBD_TABIX
                                        0.
    This Was the Error some how 0 was there we are removed the 0 now it is working fine
    Rgds
    Thomson

  • How to get class name of a object in run time, from its accessible context.

    Hi,
    I need to get the class name of a java object in run-time, given the AccessibleContext of that object.
    I gone through the AccessibleContext api documentation. but there is not way to get the class name for a java object using its AccessibleContext object.
    Do any one have any idea how to get the class name of an java object, given its accessible object Accessible.
    Thanks
    Timberlake

    816311 wrote:
    Please try to provide a solution for my requirement and avoid evaluating a requirement.
    I am a curious guyit's great to be curious. however, in this situation, the requirement makes no sense in the given context. so, in an effort to be helpful, the people on this forum are asking you the reason behind the requirement. the reason we do this is because we have experience answering questions on this forum and, more often than not, requirements which don't make sense are the result of misunderstandings or confusion on the part of the person making the requirement. if we can figure out why you want to do what you want to do, we may be able to point you in a direction which makes more sense.

  • How to get info from a .class file at run time? thanks for help

    I need to get methods and properties (variables) from a .class file at run time.
    as u know, javap.exe can do that in an independent way. but i need to get info at run time once the .class or packeges have been changed, javap is not suitable in the case.
    i try to read data directly from .class file but it's hard to know the file format.
    e.g. a class looks like (java file):
    class MyClass extends Frame
    int i0;
    String s0;
    public String getName()
    if the file is compiled to .class file, how to get properties (variables: i0,s0) and methods String getName() from the .class file by an applicaton at run time?
    Doclet is not suitable for speed reason, it is too slow to get right info in right format.
    Thanks for any help, please write a little bit more in detail if you know.

    Use the Java Reflection API. Have a look at the Reflection section of the Java Tutorial located at http://java.sun.com/docs/books/tutorial/reflect/index.html

  • Load Jar and access a class in jar at run time

    I need help from you.
    How to load a Jar and access a class in the jar at run time?
    When i try the following code it works fine while running in Java (Jdk1.5).If iam running the same code in servlet,ClassCastException occurs.
    Error Message : ClassCastExcption : jartest1 cannot be cast to Thing
    test.jar contains jartest.class and Thing.class
    jartest1.java
    try{
    File file =new File("test.jar");
    String lcStr ="jartest";
    URL jfile = new URL("jar", "", "file:" + file.getAbsolutePath() +"!/");
    URLClassLoader cl = URLClassLoader.newInstance(new URL[] { jfile });
    Class loadedClass = cl.loadClass(lcStr);
    Thing t=(Thing)loadedClass.newInstance();
    t.execute();
    catch(Exception e)
    System.err.println(e);
    Thing.java
    public interface Thing
    void execute();
    jartest.java
    public class jartest implements Thing
    public void exceute()
    System.out.println("Welcome");
    Thanks and Regards
    V.Senthil Kumar
    Edited by: senthilv_sun on Dec 16, 2008 8:30 PM

    senthilv_sun wrote:
    I need help from you.
    How to load a Jar and access a class in the jar at run time?
    When i try the following code it works fine while running in Java (Jdk1.5).If iam running the same code in servlet,ClassCastException occurs.
    Error Message : ClassCastExcption : jartest1 cannot be cast to ThingPresumably we can only hope that that is a transciption error. It always helps to use copy and past actual errors and code rather than manually typing them.
    test.jar contains jartest.class and Thing.classWrong.
    The interface class and plugable class must not be in the same jar.
    A plugable interface requires two components
    - Interface (generic sense)
    - Functional components.
    The Interface must be independant (own jar) so that it is available to the framework (user of plugin) and to the functional components. And the plugable component must not be on the java class path.
    This also means that we know for certain that the plugable component is also on the system class path. That is a bad idea as well.
    Given that it is pretty pointless to even speculate as to why this error is showing up. Create the correct jar layout. Test using the command line. Then test using servlets. Insure that the plugable jar is NOT on the java classpath for both tests.

  • Combining LVOOP DVR with Asynchronous Dynamic Dispatch and Preserve Run-Time Class

    OK, the title sounds like a cornucopia of LVOOP terms.  But there's a reason.  This is in a way an extension of THIS thread.
    What I'm doing recently is creating a LVOOP approach to loading Completely Asynchronous UI elements into subpanels.  This I have combined with a global repository for the objects (which are essentially singletons with a UI functionality) which are shared via DVR, thus eliminating a lot of synchronisation headaches).
    This means that I can ahve a universal framework for launching the UI elements into a subpanel.  The changes made on the Object there are automatically reflected in the global repository.
    So far so good.
    What I don't like too much is a combination of two seemingly awkward code constructs I need in order to keep things running.
    Weird construct 1:
    I have defined a "Launch UI" function in my parent class which is Dynamic Dispatch (Allowing each object to take care of launching its own UI).  This takes a parent object DVR as a second input which I make sure is of the exact same type as the object type being invoked by using the code shown below.  The ACTUAL Type of both inputs to the launch VI within the IPE are identical.  This is guaranteed because I require each new class to override this function.
    Here I pass the DVR from outside the IPE to the "Launch" VI but the Object obtained within the IPE retains information required for DD thus ensuring that the VI called for launching the UI is identical to the ACTUAL object type in the DVR.  This works OK and by placing this weird construct WITHIN the parent class, abuse is minimised, it works fine and seems to have no major side-effects.
    So now we have a VI running asynchronously in the background which belongs to a specific object but has a DVR which it *thinks* is of a Parent Type but, because of the steps taken earlier, is actually of the same type as the object itself.
    In order to make use of the functionality defined in this actual object type, I need to continuously re-interpret the Object within the IPE as shown below.  Otherwise only the Parent functionality is available.
    If I am accessing only methods of the parent class, then the Preserve functionality is not needed.
    Is there a more elegant way to do this?  I find the net result of this code and type-juggling to be really useful and much easier to manage than the non-DVR route since the synchronisation issues disappear.  By making the IPE usage near-atomic we remove the chances of deadlock.
    All editing done in the UI of the asynchronous VI is reflected automatically in any subsequent usage of the DVR.  Even if the DVRs are not shared between VIs, this makes (for me) the headache of synchronisation easier.  If you start expanding this beyond the limits of a single VI, the benefits in Synchronisation become really huge.  You can even have multiple UI objects operating on the same data in the background without extra synchronisation needs.  The only synchronisation required is a global "Data updated" for the object in question whereby the UI elements simply update their indicators and controls from the DVR again.  This is trivial.
    Thus I am convinced that the net result of this is very beneficial.
    My question is if there's a better, safer or more "official" way to do this?
    I was about to start a new Idea for combining the "Preserve Run time Class" and the DVR Terminal of the IPE so that the casting is done automatically.  We could then have a double input to the IPE, the DVR (of base type) plus the ACTUAL Type of the object but of course returning an error if the types are incompatible.  It would be like an "Imposter" DVR input for the IPE which allows a re-interpretation of the object type.
    Would all of this go away if we allowed Dynamic Dispatch to work with DVRs?  Probably.
    Shane
    Say hello to my little friend.
    RFC 2323 FHE-Compliant
    Solved!
    Go to Solution.

    You guys rock!
    I didn't even think of casting the DVR like that.  Kinds stupid of me but I never would have thought it would work.  Cool.
    Also, Yeah, the limitation of no IPE in the Launch VI was one I spotted quite early on.  this is why my Launch VI also doesn't accept more data than is absolutely neccessara because a DVR access in that VI will of course cause a lockup.  I have the system so far now that I can have a SINGLE Launch VI (Which is NOT overridden, so the limitation refers to only a single VI now which is certainly better.
    So again guys, thanks for helping out an old newbie.  I've been around for quite a while, have made many posts but I love the way I just keep learning from others in the Forum.  This is just why I absolutely LOVE it here. 
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Reading from a file. How to ask the user for file name at run time????

    I have the code to read from a file but my problem is how to prompt the user for the file name at run time.
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class FileRead {
        public static void main(String args[]) {
            Scanner scan = null;
            File file = new File("Results.txt");
            String number;
            try {
                scan = new Scanner(file);
                while (scan.hasNext()){
                number = scan.next();
                System.out.println(number);}
            catch (FileNotFoundException ex1){
                System.out.println("No such file");
            catch (IllegalStateException ex2){
                System.out.println("Did you close the read by mistake");
            catch (InputMismatchException ex){
                System.out.println("File structure incorrect");
            finally{
                scan.close();}
    }Any hints would be greatly appreciated. Thank you in advance

    I have read through some of the tutorials that you have directed me too and they are very useful, thank you. however there are still a few things that i am not clear about. I am using net beans 5.0 I have placed a text file named Results.txt into the project at the root so the program can view it.
    When I use the code that you provided me with, does it matter where the file is, or will it look through everywhere on the hard drive to find a match?
    This code compiles but at run time it comes up with this error
    run-single:
    java.lang.NoClassDefFoundError: NamedFile
    Exception in thread "main"
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    import java.util.Scanner;
    import java.io.*;
    class NamedFileInput
      public static void main (String[] args) throws IOException
        int num, square;   
        // this Scanner is used to read what the user enters
        Scanner user = new Scanner( System.in );
        String  fileName;
        System.out.print("File Name: ");
        fileName = user.nextLine().trim();
        File file = new File( fileName );     // create a File object
        // this Scanner is used to read from the file
        Scanner scan = new Scanner( file );     
        while( scan.hasNextInt() )   // is there more data to process?
          num = scan.nextInt();
          square = num * num ;     
          System.out.println("The square of " + num + " is " + square);
    }his is the code that i used. It is the same as the code you posted for me (on chapter 23 I/O using Scanner and PrintStream) Sorry im just really stuck on this!!

Maybe you are looking for