Runtime casting problems

The following code gives me runtime casting problems:
package edu.columbia.law.markup.test;
import java.util.*;
public class A {
   protected static Hashtable hash = null;
   static {
      hash = new Hashtable ();
      hash.put ("one", "value 1");
      hash.put ("two", "value 2");
   public static void main (String args []) {
       A a = new A ();
       String keys [] = a.keys ();
       for (int i = 0; i < keys.length; i++) {
           System.out.println (keys );
public String [] keys () {
return (String []) hash.keySet ().toArray ();
The output on my console is:
java.lang.ClassCastException: [Ljava.lang.Object;
        at edu.columbia.law.markup.test.A.keys(A.java:37)
        at edu.columbia.law.markup.test.A.main(A.java:29)I can not understand why is it a problem for JVM to cast?
Any ideas?
Thanks,
Alex.

return (String []) hash.keySet ().toArray ();This form of toArray returns an Object[] reference to an Object[] object. You cannot cast a reference to an Object[] object to a String[] reference for the same reason that you cannot cast a reference to a Object object to a String reference.
You must use the alternate form of toArray instead:
return (String []) hash.keySet ().toArray (new String[0]);This will return an Object[] reference to a String[] object, and this reference can be cast to a String[] reference.

Similar Messages

  • Runtime Casting

    I have a hashtable with different objects types inside it. Since they are swing objects, all of them are handled by a single function.
    Enumeration enum = hash.keys();
    while( enum.hasMoreElements() )
         // The key is always a String, so a hard cast is acceptable
         String key = (String)enum.nextElement();
         Object val = hash.get(key);
         // Try Use Reflection to retrieve the class
         Class interfaceClass = Class.forName(val);    // ??
         panel.add( (interfaceClass)val  );            // ??
    }What I would like to do is cast these objects without having to write a switch statment to delimit hard casts. The following code works, but since I have to hard code the answers is *obviously a poor way to do it.
    Enumeration enum = hash.keys();
    while( enum.hasMoreElements() )
         String key = (String)enum.nextElement();
         Object val = hash.get(key);
         // Use Reflection to retrieve the class
         Class interfaceClass = val.getClass();
         String className = interfaceClass.getName();
         if( className.endsWith("JButton") )
              panel.add( (JButton)val  );
         else if( className.endsWith("JCheckBox") )
              panel.add( (JCheckBox)val  );
    }Any help with the dynamic casting problem would be appericated.
    ~Kullgen
    (PS, After searching the forums for a solution, I find that when people ask this question they are invariably flamed for poor design. This is not a design question, but just a problem with having to use the clunky java swing. IMHO Swing was very poorly designed, and thus leaves itself open to the problems above. I want this to be a post about runtime casting, not about design)

    Since all the has elements are Swing componets they are all instances
    of java.awt.Component. So simply cast to that and everything will be
    just fine and dandy. No need for lots of switch statements.
    For example:
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    public class Kullgen1
         public static void main(String[] argv)
              Hashtable hash= new Hashtable();
              hash.put("Button", new JButton("Button"));
              hash.put("Label", new JLabel("Label"));
              hash.put("TextField", new JTextField("TextField"));
              JFrame frame= new JFrame();
              JPanel panel= new JPanel(new GridLayout(0,1));
              frame.getContentPane().add(panel);
              Iterator components= hash.values().iterator();
              while(components.hasNext())
                   panel.add((Component) components.next());
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
    }

  • Will generics implementation eliminate runtime casting?

    Before generics, one must explicitly cast when pulling out of an iterator. For example:
    List l = ...
    for(Iterator i = l.iterator(); i.hasNext();) {
    doSomethingWithInteger((Integer)l.next());
    Now with generics, we won't have to explicitly cast the return value of the iterator's .next() method:
    List<Integer> l = ...
    for(Iterator i = l.iterator(); i.hasNext();) {
    doSomethingWithInteger(l.next());
    However, form what I've seen of decompiled code compiled with the beta version of the generics compiler, there is still implicit casting going on. The return value of Iterator.next() is still being casted to an Integer. And runtime casting like this has actual instructions to be executed, not just syntactic sugar. It seems silly to me, though, since everything in the List is an Integer, there should be no need to explicitly cast it.
    So will the addition of generics not be able to eliminate this overhead? Why was this decided?

    It actually turns out that the runtime casts are extremely cheap to do, because modern superscalars typically have plenty of extra functional units and branch prediction on the cast is extremely accurate (all the casts inserted by JSR-14 are always true, so the branches always predict correctly).
    But even though they have a negligible performance cost, they do bloat the binary. The NextGen proposal
    http://doi.acm.org/10.1145/286936.286958
    was always the "future" solution to this. It's the second step of the implementation. The first step is JSR-14.

  • Output Parameter cast problems

    Wondering if anyone has seen this ...
    Migrating a data access layer (based on the MS DAAB) using the ODP.NET provider. I wrote my own parameter discovery code to dynamically configure parameters at runtime - just like the SqlCommandBuilder.DeriveParameters() method does for SQL Server sprocs.
    (I query the "all_arguments" view to get this data, by the way, passing the package name and procedure name.)
    Here's the problem: you cannot discover the Size property for a parameter via this query. Bummer. So for VarChar2 and Char types I tried setting the Size to somethng big, like 2000.
    When I retrieve the parameters after an ExecuteNonQuery statement, I am getting Type cast errors:
    "Cast from type 'OracleString' to type 'String' is not valid"
    Here's the weird part:
    - CType(params(5).Value, Integer) 'WORKS
    - CType(params(2).Value, String) 'DOESN'T WORK
    - params(2).Value.ToString 'WORKS
    - CType(params(2).Value, Date) 'DOESN'T WORK
    What the ...? Why can't I cast a VarChar2 or Char type back to a .NET String? Why does ToString work but Ctype() not work?
    I hope somebody can offer guidance, I've got a lot invested in this DAL :-)
    Thanks eh
    Kurt Mang
    Vancouver BC

    There's not really an elegant way to provide these conversions in VB. In C# OracleString uses operator overloading to provide type conversions, but this version of VB doesn't support it.
    They might have implemented IConvertible on the oracle types.
    Then you could write
    Dim osw as new OracleString("Hello")
    Dim s as String = CType(osw, IConvertible).ToString
    But that's not really better than
    Dim osw as new OracleString("Hello")
    Dim s as String = osw.Value
    The long and short of it is, OracleTypes ( and other ADO.NET provider types), are special high-performance types (usually value types), and they convert using a different idiom. By convention they are converted to the corresponding framework type using a property called .Value, and constructed from framework types using a constructor.
    String s = New OracleString("Hello").Value
    Converts the Unicode string "Hello" to an OracleString structure, and then back to a unicode string.
    David

  • Class Casting problem

    hi,
    i�ve loaded a class at runtime and to parse it to another type, also loaded at runtime, but an error occures!
    in this code i dont write the try�s and catches, they doesn�t matter in this problem
    Class prototype; //source class
    Class parser;    //target class
    Class parsed;    //parsed class (source -> target / prototype -> parser)
    prototype = Class.forName("Prototype");
    parser    = Class.forName("Parser");
    parsed    = (parser) prototype; //Compiler: "Class parser not found"what does it mean?
    can somebody help me?
    thx anyway
    cu Errraddicator

    parser    = Class.forName("Parser");
    parsed    = (parser) prototype; //Compiler: "Class1st. "Parser" or "parser" ... what's the name of your class?
    2nd. all your variables are of type Class. why would you want something of type Class cast into type Parser and then assign it back to a variable of class parsed?
    try something like:
    Class parserClass = Class.forName("Parser");
    Parser parser = (Parser) parserClass.newInstance();of course this is not really THE way to construct an object if you know about the Class type beforehand....
    ulrich

  • Wide casting problem

    Hi All,
    Can u explain Wide casting in detail ? already i gone through sdn links but still i didnt get clear .  please go through the follwing code snippet and explain where i made mistake in order to getting wide casting.. my problem is as wide casting i want to access the base class methods with reference of sub class when the base class methods are redefined in sub class(actually sub class reference access the  subclass methods only if we have same methods in base and as well as sub class) in my program after performing wide cast also it is accessing sub class methods only please send the answer.
    REPORT  ZNARROW_WIDE.
    CLASS C1 DEFINITION.
    PUBLIC SECTION.
    METHODS:M1,M2.
    ENDCLASS.
    CLASS C1 IMPLEMENTATION.
    METHOD M1.
    WRITE:/ ' THIS IS SUPER CLASS METHOD M1'.
    ENDMETHOD.
    METHOD M2.
    WRITE:/ ' THIS IS SUPER CLASS METHOD M2'.
    ENDMETHOD.
    ENDCLASS.
    CLASS C2 DEFINITION INHERITING FROM C1.
    PUBLIC SECTION.
    METHODS:M1 REDEFINITION.
    METHODS:M2 REDEFINITION,
                      M3.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
    METHOD M1.
    WRITE:/ ' THIS IS SUB CLASS METHOD M1'.
    ENDMETHOD.
    METHOD M2.
    WRITE:/ ' THIS IS SUBCLASS METHOD M2'.
    ENDMETHOD.
    METHOD M3.
    WRITE:/ ' THIS IS SUB CLASS METHOD M3'.
    ENDMETHOD.
    ENDCLASS.
    DATA:O_SUPER TYPE REF TO C1,
         O_SUB TYPE REF TO C2.
    START-OF-SELECTION.
    CREATE OBJECT O_SUPER.
    CREATE OBJECT O_SUB.
    CALL METHOD O_SUPER->M1.
    CALL METHOD O_SUPER->M2.
    CLEAR O_SUPER.
    O_SUPER = O_SUB.
    CALL METHOD O_SUPER->('M3').
    SKIP 5.
    ULINE 1(80).
    CLEAR O_SUB.
    O_SUB ?= O_SUPER.
    CALL METHOD O_SUB->M1.
    CALL METHOD O_SUB->M2.
    CALL METHOD O_SUB->M3.
    Thanks in advance.
    sreenivas P

    Hi,
    consider the following sample code:
    REPORT  ZA_TEST93.
    class class_super definition.
      public section.
        data: var_area type i.
        methods:
        area importing length type i breadth type i.
    endclass.
    class class_super implementation.
      method area.
        var_area = length * breadth.
        write:/ 'Area of rectangle = '.
        write: var_area.
      endmethod.
    endclass.
    class class_sub definition inheriting from class_super.
      public section.
      data:height type i.
      methods:
      area redefinition.
    endclass.
    class class_sub implementation.
      method area.
        var_area = 6 * length * breadth * height.
        write:/ 'Area of the cube ='.
        write: var_area.
      endmethod.
    endclass.
    start-of-selection.
    data: object_superclass type ref to class_super,
          object_subclass type ref to class_sub,
          object2_superclass type ref to class_super.
    create object object_superclass.
    create object object2_superclass.
    create object object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    "Narrow casting
    object_subclass->height = 10.
    object_superclass = object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 10.
    "Wide casting
    object_superclass ?= object2_superclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    Explanation:
    In the above code, consider the super class named 'class_super'.
    This class has a method called 'area' which is used to calculate the area of a rectangle.
    Consider the subclass 'class_sub', which inherits all the attributes and methods of super class 'class_super'.
    Now we want to use the same method of super class 'class_super', 'area', but this time we want it to calculate the area of a cube.
    For this purpose we use the 'redefinition' keyword in the definition part of 'class_sub' and enter the code for cube area calculation in the 'area' method body in the implementation part of 'class_sub'.
    From the above code, consider the following code snippet:
    create object object_superclass.
    create object object2_superclass.
    create object object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    Explanation: Two objects of the superclass and one object of the subclass are created and the 'area' method of the superclass is called to compute the area of a rectangle.
    Now consider what comes next:
    "Narrow casting
    object_subclass->height = 10.
    object_superclass = object_subclass.
    call method object_superclass->area exporting length = 10 breadth = 10.
    Explanation:
    We assign a value of 10 to the 'height' instance variable of the subclass object.
    Then we perform narrow casting in the next line(object_superclass = object_subclass.).
    Now the instance of the superclass(object_superclass) now points or refers to the object of the subclass, thus the modified method 'area' of the subclass is now accessible.
    Then we call this method 'area' of the subclass to compute the area of the cube.
    Moving on to the final piece of code:
    "Wide casting
    object_superclass ?= object2_superclass.
    call method object_superclass->area exporting length = 10 breadth = 5.
    Explanation:
    The object 'object_superclass' now refers to the object of the subclass 'object_subclass'.
    Thus the 'area' method of the superclass cannot be called by this object.
    In order to enable it to call the 'area' method of the superclass, wide casting has to be perfomed.
    For this purpose, the RHS of the wide casting must always be an object of a superclass, and the LHS of the wide casting must always be an object reference declared as 'type ref to' the superclass(objectsuperclass ?= object2_superclass.)._
    Otherwise a runtime error will occur.
    Finally the 'area' method of the superclass can now be called once again to compute the area of the rectangle.
    The output of the above example program is as follows:
    Area of rectangle =          50
    Area of the cube =      6,000
    Area of rectangle =          50
    Also note that wide casting cannot be performed on subclass objects, wide casting can only be performed on superclass objects that have been narrow cast.
    Hope my explanation was useful,
    Regards,
    Adithya.
    Edited by: Adithya K Ramesh on Dec 21, 2011 11:49 AM
    Edited by: Adithya K Ramesh on Dec 21, 2011 11:51 AM

  • Java.lang.Runtime.exec problem in ubuntu 9.10

    Hi:
    I tried to run some command in the java code , for example "grass64 -text /home/data/location", this command works well in the terminal, however when I call it in the java code I got some excepetions.
    My code is :
    public class Grass {
         public static String grassBatJob="GRASS_BATCH_JOB";
         public void run(String cmd,String jobPath) {
              //set the environments variables
              Map<String, String> env=new HashMap<String, String>();
              env.put(grassBatJob, jobPath);
              String gisDataBase="/home/kk/grass/GrassDataBase";
              String location="spearfish60";
              String mapset="PERMANENT";
              cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
              CommandLine line=new CommandLine(cmd);
              //the real cmd should be >>grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT
              System.out.println("start line=="+line.toString());
              DefaultExecutor de=new DefaultExecutor();
              try {
                   int index=de.execute(line,env);
                   System.out.println(index);
              } catch (ExecuteException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              String jobPath=Grass.class.getResource("grass.sh").getFile();
              new Grass().run("grass64 -text", jobPath);
    The real cmd I want to execute is "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in my application I got the exception"
    java.io.IOException: Cannot run program "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException: error=2, No such file or directory
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
         at java.lang.Runtime.exec(Runtime.java:593)
         at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
         at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
         at org.kingxip.Grass.run(Grass.java:27)
         at org.kingxip.Grass.main(Grass.java:38)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
         at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
         at java.lang.ProcessImpl.start(ProcessImpl.java:65)
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
         ... 7 more
    I wonder why?

    Thanks for all of your reply, and now I can run the command, however I met some problems when I tried to get the result of the exec.
    The core codes are shown below:
    String cmd="g.version";
    String[] exe={"bash","-c",cmd};
    Process p1=Runtime.getRuntime.exec(exe,env); // the env has been set
    GrassThread outThread=new GrassThread("out", p1.getInputStream());
    outThread.start();
    GrassThread errorThread=new GrassThread("error", p1.getErrorStream());
    errorThread.start();
    int exitVal = p1.waitFor();
    String resu=outThread.sb.toString();
    System.out.println("==========the output start========");
    System.out.println(resu);
    System.out.println("==========the output end========");
    System.out.println("ExitValue: " + exitVal); //------------------> line one
    public class GrassThread extends Thread{
         public StringBuffer sb=new StringBuffer();
         public GrassThread(String type,InputStream is) {
              this.type=type;
              this.is=is;
         public void run() {
              try {
                   InputStreamReader isr = new InputStreamReader(is);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ((line = br.readLine()) != null) {
                        System.out.println(type + ">" + line);
                        sb.append(line).append("\r");  // ----------------------------> line two
    }I define a StringBuffer in the GrassThread to save the output (see the code where I marked by "line two"), and when the process complete, I check the StringBuffer to get the output (see code where I marked by "line one"), however the output in the console of the IDE are :
    ----------- output in the console of the IDE start -------------
    ==========the output start========
    ==========the output end========
    ExitValue: 0
    out>GRASS 6.4.0RC5 (2009)
    ----------output in the console of the IDE end--------------------
    I can not understand, in the code "line one", I first get the output using "System.out.println(resu);",then I print the exitvalue,but why the order of the output in the console is not what I expected?
    Another question, the code above assume the output can be got from the Process's getInputStream, however sometimes the output maybe come from the Process's getErrorStream, so how to handle it?
    Edited by: apachemaven on 2010-3-5 ??5:38

  • Runtime.exec problem

    we have a c program which does the encryption on the input files.
    IF we ran this program in unix os, it will take 30 secs to finish.
    But if we call this program using java by calling Runtime.getRuntime().exec(command)
    it takes 20 minutest to finish.
    We wonder why does it take this much time to finish.
    We are having thought that when the program runs in unix os it can get all the resources it want.
    but when run this through java, it is limited to JRE / JVM memory size. --->Am I right?
    Could you please clarify my doubt on the memory size. If I wrong, how can we fix this problem.
    Thanx

    In the case of unix
    u will just run the executable using a.out. For processor its just the execution of the executable, so 30 secs
    In case of java
    step1: It has to interpret the java program line by line after doing required loading, linking and initialization
    of the required libraries and class files.
    step2: It has to create a separate process using Runtime.getRuntime().exec() and wait for the result
    of that process
    so the total time will be step1 + step2 = some time + 30 sec = 20 minutes.

  • Casting problems getting a home I/F of an EJB in another app when debuging a servlet

    (Jdeveloper version = 9.0.2.798, OC4J Application Server version = Oracle9iAS (9.0.2.0.0))
    I am trying to debug a multi-tier application using the embedded application server. Servlets and EJBs within that application need to call EJBs contained within a second application (Horus).
    I have set up the embedded application server to run this second application automatically by adding the following entry into its server.xml
    <application auto-start="true" name="Horus" path="M:\Studio\build\production\java\Server\Obfuscate\J2EE_HOME\Horus\Horus.xml"/>
    I then start the embedded application server by debugging my servlet project, 'intermediateServlet'. I know the second application is running correctly in the embedded application server because I can access it from a separate client.
    In the 'intermediateServlet', I want to obtain a reference to a Dispatcher EJB held in the Horus application. This EJB has the following properties
         ejb-name     = com.internal.server.Dispatcher
         home interface     = com.internal.server.DispatcherHome
         bean class     = com.internal.server.DispatcherEJB
         remote interface= com.internal.server.Dispatcher
    The following code is executed during the container's call to my servlet init( context ) method to try and get the appropriate home interface.
    Context context = null;
    Object tempRemoteIF1 = null;
    Object tempRemoteIF2 = null;
    Properties h = null;
    h = new Properties();
    h.put( Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory" );
    h.put( Context.PROVIDER_URL, "ormi://127.0.0.1:23891/Horus");
    h.put( Context.SECURITY_PRINCIPAL, "user0" );
    h.put( Context.SECURITY_CREDENTIALS, "password" );
    context = new InitialContext (h);
    tempRemoteIF1 = context.lookup( "com.internal.server.Dispatcher" );
    tempRemoteIF2 = javax.rmi.PortableRemoteObject.narrow
    tempRemoteIF1,
    Class.forName( "com.internal.server.DispatcherHome" )
    The context.lookup call seems to work fine, returning an object of the class
         DispatcherHome_StatelessSessionHomeWrapper5
    Which I presume is a containter generated class implementing the home interface. To help confirm this,
    the object has a property beanName that has the value "com.internal.server.Dispatcher".
    The problem occurs on the next line, when I check whether I can cast the object to the home interface using ProtableRemoteObject.narrow(). This gives the following exception.
    java.lang.ClassCastException
         java.lang.Object com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
              PortableRemoteObject.java:296
         java.lang.Object javax.rmi.PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
              PortableRemoteObject.java:137
         com.internal.server.Dispatcher com.Studio.servlet.intermediateServlet.getDispatcherRef(java.lang.String, java.lang.String, java.lang.String)
              intermediateServlet.java:601
         void com.Studio.servlet.intermediateServlet.init(javax.servlet.ServletConfig)
              intermediateServlet.java:150
         com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.loadServlet(com.evermind.util.ByteString)
              HttpApplication.java:1669
         com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.findServlet(com.evermind.util.ByteString)
              HttpApplication.java:4001
         javax.servlet.RequestDispatcher com.evermind.server.http.HttpApplication.getRequestDispatcher(com.evermind.util.ByteString, com.evermind.server.http.EvermindHttpServletRequest, com.evermind.server.http.EvermindHttpServletResponse)
              HttpApplication.java:2200
         boolean com.evermind.server.http.HttpRequestHandler.processRequest(com.evermind.server.ApplicationServerThread, com.evermind.server.http.EvermindHttpServletRequest, com.evermind.server.http.EvermindHttpServletResponse, java.io.InputStream, java.io.OutputStream, boolean)
              HttpRequestHandler.java:580
         void com.evermind.server.http.HttpRequestHandler.run(java.lang.Thread)
              HttpRequestHandler.java:243
         void com.evermind.util.ThreadPoolThread.run()
              ThreadPoolThread.java:62
    Interestingly, if I use practically the same code, to obtain the home interface of an EJB that is defined in the application that I am debugging, the cast works perfectly. The returned object looks identical, apart from the name to the DispatcherHome_StatelessSessionHomeWrapper5 mentioned above.
    Could the error possibly be because I need to declare 'Horus' as a parent application of the application I am debugging? If it is how do I do this?
    Many thanks in advance for any help with this one.
    Mark.

    (Jdeveloper version = 9.0.2.798, OC4J Application Server version = Oracle9iAS (9.0.2.0.0))
    I am trying to debug a multi-tier application using the embedded application server. Servlets and EJBs within that application need to call EJBs contained within a second application (Horus).
    I have set up the embedded application server to run this second application automatically by adding the following entry into its server.xml
    <application auto-start="true" name="Horus" path="M:\Studio\build\production\java\Server\Obfuscate\J2EE_HOME\Horus\Horus.xml"/>
    I then start the embedded application server by debugging my servlet project, 'intermediateServlet'. I know the second application is running correctly in the embedded application server because I can access it from a separate client.
    In the 'intermediateServlet', I want to obtain a reference to a Dispatcher EJB held in the Horus application. This EJB has the following properties
         ejb-name     = com.internal.server.Dispatcher
         home interface     = com.internal.server.DispatcherHome
         bean class     = com.internal.server.DispatcherEJB
         remote interface= com.internal.server.Dispatcher
    The following code is executed during the container's call to my servlet init( context ) method to try and get the appropriate home interface.
    Context context = null;
    Object tempRemoteIF1 = null;
    Object tempRemoteIF2 = null;
    Properties h = null;
    h = new Properties();
    h.put( Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory" );
    h.put( Context.PROVIDER_URL, "ormi://127.0.0.1:23891/Horus");
    h.put( Context.SECURITY_PRINCIPAL, "user0" );
    h.put( Context.SECURITY_CREDENTIALS, "password" );
    context = new InitialContext (h);
    tempRemoteIF1 = context.lookup( "com.internal.server.Dispatcher" );
    tempRemoteIF2 = javax.rmi.PortableRemoteObject.narrow
    tempRemoteIF1,
    Class.forName( "com.internal.server.DispatcherHome" )
    The context.lookup call seems to work fine, returning an object of the class
         DispatcherHome_StatelessSessionHomeWrapper5
    Which I presume is a containter generated class implementing the home interface. To help confirm this,
    the object has a property beanName that has the value "com.internal.server.Dispatcher".
    The problem occurs on the next line, when I check whether I can cast the object to the home interface using ProtableRemoteObject.narrow(). This gives the following exception.
    java.lang.ClassCastException
         java.lang.Object com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
              PortableRemoteObject.java:296
         java.lang.Object javax.rmi.PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
              PortableRemoteObject.java:137
         com.internal.server.Dispatcher com.Studio.servlet.intermediateServlet.getDispatcherRef(java.lang.String, java.lang.String, java.lang.String)
              intermediateServlet.java:601
         void com.Studio.servlet.intermediateServlet.init(javax.servlet.ServletConfig)
              intermediateServlet.java:150
         com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.loadServlet(com.evermind.util.ByteString)
              HttpApplication.java:1669
         com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.findServlet(com.evermind.util.ByteString)
              HttpApplication.java:4001
         javax.servlet.RequestDispatcher com.evermind.server.http.HttpApplication.getRequestDispatcher(com.evermind.util.ByteString, com.evermind.server.http.EvermindHttpServletRequest, com.evermind.server.http.EvermindHttpServletResponse)
              HttpApplication.java:2200
         boolean com.evermind.server.http.HttpRequestHandler.processRequest(com.evermind.server.ApplicationServerThread, com.evermind.server.http.EvermindHttpServletRequest, com.evermind.server.http.EvermindHttpServletResponse, java.io.InputStream, java.io.OutputStream, boolean)
              HttpRequestHandler.java:580
         void com.evermind.server.http.HttpRequestHandler.run(java.lang.Thread)
              HttpRequestHandler.java:243
         void com.evermind.util.ThreadPoolThread.run()
              ThreadPoolThread.java:62
    Interestingly, if I use practically the same code, to obtain the home interface of an EJB that is defined in the application that I am debugging, the cast works perfectly. The returned object looks identical, apart from the name to the DispatcherHome_StatelessSessionHomeWrapper5 mentioned above.
    Could the error possibly be because I need to declare 'Horus' as a parent application of the application I am debugging? If it is how do I do this?
    Many thanks in advance for any help with this one.
    Mark. Try loading the home interface from the same classloader used to load the the returned home object.
    tempRemoteIF2 = javax.rmi.PortableRemoteObject.narrow
    ( tempRemoteIF1,
    tempRemoteIF1.getClass().getClassLoader().loadClass("com.internal.server.DispatcherHome" )
    Dhiraj

  • Class casting problems in JSP's

    Folks,
              Several people, including myself, have written about the problems they
              ran into when trying to cast a class in JSP's. The following link might
              provide the answer:
              http://www.weblogic.com/docs51/classdocs/API_jsp.html#sessions
              I believe this is a major limitation Weblogic put on web app
              development, and hope BEA would eventually find a way to allow non-user
              defined types being stored in servlet sessions.
              Jeff
              

    Folks,
              Several people, including myself, have written about the problems they
              ran into when trying to cast a class in JSP's. The following link might
              provide the answer:
              http://www.weblogic.com/docs51/classdocs/API_jsp.html#sessions
              I believe this is a major limitation Weblogic put on web app
              development, and hope BEA would eventually find a way to allow non-user
              defined types being stored in servlet sessions.
              Jeff
              

  • 10gr2 TABLE(CAST( problem

    We have an existing report that uses existing function to table cast back data in the from clause. A very simplified example:
    FROM grant g, grantparticipant gt, table(cast(getSchedule(g.grant_pk, gt.grantparticipant_pk) as r_sched)) sched
    where g.grant_pk = gt.grant_fk
    and sched.grantparticipant_pk = gt.grantparticipant_pk
    The grantparticipant_pk is NULL when captured in the function. There are no null values in the table (it's a primary key). When the where clause is changed to reference a specific pk it works fine and the value is filled in.
    The works in our production db where the Oracle version is 10g. It works in development which is also 10g. The problem only appears to be with our 10gr2 DB.
    Any ideas....

    The problem was solved with ANSI JOINs. Would still like to know why that problem occurred?

  • Shareable object interface cast problem

    Hi,
    I'm a student working on building a shareable object interface between two applets namely "EWallet" and "EPhone".
    I currently use the javacard 2.2.X version and I mean to solve the shareable object interface in this version.
    Thus not with servlets in 3.X.X.
    The current problem I'm facing is the casting from the base type of shareable interface objects (Shareable) to the EWalletInterface which I need to do operations on the SIO of EWallet.
    The code snippet of the EWallet applet (server)
    public void verify(byte[] pincode) {
    if ( pin.check(pincode, (short)0,(byte)(short)pincode.length) == false )
    ISOException.throwIt(SW_VERIFICATION_FAILED);
    public void debit(byte debitAmount) {
    if (!pin.isValidated())
    ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
    // check debit amount
    if ((debitAmount > MAX_TRANSACTION_AMOUNT) || (debitAmount < 0))
    ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
    // check the new balance
    if ((short)(balance - debitAmount) < (short)0)
    ISOException.throwIt(SW_NEGATIVE_BALANCE);
    balance = (short)(balance - debitAmount);
    public Shareable getShareableInterfaceObject(AID client_aid, byte parameter){
    byte[] ephone_aid_bytes = {(byte)0X15, (byte)0XEF, (byte)0X4D, (byte)0X55, (byte)0X86, (byte)0X60};
    if(client_aid.equals(ephone_aid_bytes,(short)0,(byte)ephone_aid_bytes.length) == false)
    return null;
    if(parameter != (byte)0x01)
    return null;
    return this;
    The code snippet of the EPhone applet (client)
    //Helper method
    private void makeBankcardDebit(short amount){
    AID ewallet_aid = JCSystem.lookupAID(ewallet_aid_bytes,(short)0,(byte)ewallet_aid_bytes.length);
    if(ewallet_aid == null)
    ISOException.throwIt(SW_EWALLET_AID_NOT_EXIST);
    //Error with casting from Shareable to EWalletInterface
    EWalletInterface sio = (EWalletInterface)(JCSystem.getAppletShareableInterfaceObject(ewallet_aid, (byte)0x01));
    if(sio == null)
    ISOException.throwIt(SW_FAILED_TO_OBTAIN_SIO);
    byte[] pin = new byte[4];
    sio.verify(pin);
    sio.debit((byte)amount);
    this.balance = (short)(this.balance + amount);
    The EWalletInterface code snippet
    public interface EWalletInterface extends Shareable {
    public void verify(byte[] pincode);
    public void debit(byte amount);
    The interface is currently both in the EWallet and EPhone packages.
    The problem i'm facing is that in the code snippet of EPhone.
    The "lookupAID"- and "getAppletShareableInterfaceObject"-methods work
    The casting from Shareable to EWalletInterface gives me status word 0x6F00 which presents me with a google explanation of "No precise diagnosis".
    Does anyone have an idea why the cast from Shareable to EWalletInterface doesn't work?
    Thanks in advance,
    Jeroen

    Hi,
    What happens if you get the SOI reference and store in a Shareable and see if it is null? Just to confirm, the two applets are in different packages and the server applet has be installed and is selectable?
    If you get 0x6F00, you should start adding try/catch blocks to find the root cause.
    Cheers,
    Shane
    =================================
    Reposting with &#123;code} tags
    =================================
    Hi,
    I'm a student working on building a shareable object interface between two applets namely "EWallet" and "EPhone".
    I currently use the javacard 2.2.X version and I mean to solve the shareable object interface in this version.
    Thus not with servlets in 3.X.X.
    The current problem I'm facing is the casting from the base type of shareable interface objects (Shareable) to the EWalletInterface which I need to do operations on the SIO of EWallet.
    The code snippet of the EWallet applet (server)
        public void verify(byte[] pincode) {
            if ( pin.check(pincode, (short)0,(byte)(short)pincode.length) == false )
                ISOException.throwIt(SW_VERIFICATION_FAILED);
        public void debit(byte debitAmount) {
            if (!pin.isValidated())
                ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
            // check debit amount
            if ((debitAmount > MAX_TRANSACTION_AMOUNT) || (debitAmount < 0))
               ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
            // check the new balance
            if ((short)(balance - debitAmount) < (short)0)
                 ISOException.throwIt(SW_NEGATIVE_BALANCE);
            balance = (short)(balance - debitAmount);
        public Shareable getShareableInterfaceObject(AID client_aid, byte parameter){
            byte[] ephone_aid_bytes = {(byte)0X15, (byte)0XEF, (byte)0X4D, (byte)0X55, (byte)0X86, (byte)0X60};
            if(client_aid.equals(ephone_aid_bytes,(short)0,(byte)ephone_aid_bytes.length) == false)
                return null;
            if(parameter != (byte)0x01)
                return null;
            return this;
    The code snippet of the EPhone applet (client)
       //Helper method
        private void makeBankcardDebit(short amount){
            AID ewallet_aid = JCSystem.lookupAID(ewallet_aid_bytes,(short)0,(byte)ewallet_aid_bytes.length);
            if(ewallet_aid == null)
               ISOException.throwIt(SW_EWALLET_AID_NOT_EXIST);
            //Error with casting from Shareable to EWalletInterface
            EWalletInterface sio = (EWalletInterface)(JCSystem.getAppletShareableInterfaceObject(ewallet_aid, (byte)0x01));
            if(sio == null)
              ISOException.throwIt(SW_FAILED_TO_OBTAIN_SIO);
            byte[] pin = new byte[4];
            sio.verify(pin);
            sio.debit((byte)amount);
            this.balance = (short)(this.balance + amount);
    The EWalletInterface code snippet
        public interface EWalletInterface extends Shareable {
            public void verify(byte[] pincode);
            public void debit(byte amount);
        }The interface is currently both in the EWallet and EPhone packages.
    The problem i'm facing is that in the code snippet of EPhone.
    The "lookupAID"- and "getAppletShareableInterfaceObject"-methods work
    The casting from Shareable to EWalletInterface gives me status word 0x6F00 which presents me with a google explanation of "No precise diagnosis".
    Does anyone have an idea why the cast from Shareable to EWalletInterface doesn't work?
    Thanks in advance,
    Jeroen

  • Runtime error problem - Premiere Pro CS5

    Just ran into a problem when trying to export a timeline as an .avi file. The process goes much more slowly than usual and when the progress bar gets to 95% an error message window opens. The title of the error is: Microsoft Visual C++ Runtime Library. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Then, I have no choice but to close Premiere.
    I foolishly downloaded and intalled some Windows 7 updates over the weekend and am assuming they might be the culprit(s). I rolled by the system to a restore point immediately before the download, but still have the problem. Any ideas on how to correct this? Of course this happens as I'm trying to export two finished videos to show to a client today. I'm running Windows 7, 64-bit.
    Thanks, Steve Pender

    This may help:
    http://kb2.adobe.com/cps/403/kb403090.html
    I've also noticed that bearly all instances of this error come from bad versions of third-party components like drivers, so I recommend updating your drivers.

  • Runtime.exec() - Problem when using cvs-command

    I have a problem with the Runtime.getRuntime().exec() - Command. I try to execute a command to export files from our cvs-repository. As you hopefully know, cvs produces a lot of output.
    When I start my 'cvs export ... '- command from the console-window of windows, everything works perfect. But when I try to use the Runtime.getRuntime().exec("CVS export ...") the created cvs-subprocess stops after the export of the first three files. When I close the main-window, where the cvs-process was started from, the cvs-process continues working.
    I could see, that many others had the same problem, but I couldn't find a real solution there.
    Is there a possibility to clear/delete the output-buffer of the cvs-subprocess, because I don't really need the information, that cvs gives me. It is enough for me when cvs stores the files :-)
    My source:
    public void executableTest()
    Runtime run = Runtime.getRuntime();
    try
    Process cvsProcess = run.exec("cvs export .... ");
    cvsProcess.waitFor();
    BufferedReader in = new BufferedReader
              ( new InputStreamReader(cvsProcess.getInputStream()) );
         String line;
         while ((line = in.readLine()) != null)
              System.out.println(line);
         catch (Exception e)
         System.out.println(e.getMessage());
    Thanks for your help.

    if the buffer is overflowing, then you don't want to do the waitfor until after you've hit the end of the inputstream, me thinks.

  • Urgent: runtime error problem

    hi,
    iam working on development server and when i run a tcode and aftere dat when i press f1 for help on any field den a runtime error occurs.
    saying dat :-
      The current ABAP/4 program terminated due to
      an internal error in the database interface.
    what does it mean and how to solve dis problem,if find useful he or she will be definately rewarded.

    Hi ric,
    Can you please provide more details like type of program, type of screen. (whether you have used call screen or it's standard selection-screen)..
    Regards,
    Mohaiyuddin

Maybe you are looking for

  • Question marks in instrumentation library

    I'm running labview 5.1. All of a sudden, when I pop up my functions palette, the instrument drivers show up as a question mark. I've got all the files in the proper directory: \labview\instr.lib I know it's a dumb questions, but I can't figure how t

  • Error: Imported bank file format does not correspond to selected format

    Hi All, I am trying to execute FF.5 transaction - Import Electronic Bank Statement - for brazilian bank (Banco do Brasil) but I got an error message no. 8B795 (Imported bank file format does not correspond to selected format), I tried format B (Cobra

  • Do we need to run patch-config and install-newconfig

    Hi Team, I have a scenario wherein I have installed the JES2005Q4 messaging server : bash-3.00# ./imsimta version Sun Java(tm) System Messaging Server 6.2-3.04 (built Jul 15 2005) libimta.so 6.2-3.04 (built 01:43:03, Jul 15 2005) SunOS sunjes22 5.10

  • Need to get display only mode in ess

    Hello experts, What settings should I use so that on the ESS Personal Profile the users get a display only profile with a details button on the right as shown in the image. Currently the details only show up when somebody is maintaining the PERNR fro

  • Rebate agreement setup in SAP based on quantity purchased

    Hi Experts, Question relating to rebates and commission. I have requirement to create rebate agreement on quantity purchased. If customer buys 1KG of material then the unit of measurment i.e., KG should be conveted to Pound and accrue $2.54 per pound