ClassNotFoundException when using Class.forName(), thx

in a study app, i try to use Class.forName() to load any class then get its properties (fields, methods etc. vs reflect).
the (Frame based) app is in directory:
c:\app\StudyApp.class
there is a "Open class" button on the app, click the button, i use FileChooser to open any class file.
i.e. open a class (assume it is not packaged)
d:\dir\TheClass.class
coding in StudyApp.java is:
Class cls=Class.forName("TheClass");
now a ClassNotFoundException throws when call Class.forName() above.
it is easy to understand why throw the exception because i never tell where the class is. it is in directory
d:\dir
my question is: how to tell VM the directory.
the directory d:\dir can not be applied to -classpath when run java.exe StudyApp, because the directory is random one at run-time.
i tried to change System property (i.e. "java.class.path", 'user.dir" etc. none of them can fix the problem.
thanks in advance for any help

This probably does a lot more than you need:
import java.util.*;
import java.io.*;
import java.util.jar.*;
import java.lang.*;
public class ClassFileFinder extends ClassLoader
     List cpath = new LinkedList();
     void addFile(File f) {
          if(f.isDirectory() || (f.isFile() && f.canRead() &&
                                      f.getName().endsWith(".jar")))
               cpath.add(f);
     public byte[] classData(String className)  {
          String cname = className.replace('.', File.separatorChar) + ".class";
          Iterator it = cpath.iterator();
          while(it.hasNext()) {
               File f = (File)it.next();
               try {
                    if(f.isDirectory()) {
                         File cFile = new File(f, cname);
                         if(cFile.isFile()) {
                              byte[] buf = new byte[(int)cFile.length()];
                              InputStream in = new FileInputStream(cFile);
                              int off  = 0, l;
                              while((l = in.read(buf, off, buf.length - off)) > 0) {
                                   off += l;
                                   if(off >= buf.length) break;
                              in.read(buf);
                              in.close();
                              return buf;
                    } else if (f.isFile()) {
                         JarFile jar = new JarFile(f);
                         JarEntry ent = jar.getJarEntry(cname);
                         if(ent != null) {
                              byte[] buf = new byte[(int)ent.getSize()];
                              int off = 0, l;
                              InputStream in = jar.getInputStream(ent);
                              while((l = in.read(buf, off, buf.length - off)) > 0) {
                                   off += l;
                                   if(off >= buf.length) break;
                              in.close();
                              return buf;
               } catch (IOException e) {
          return null;          
     public Class findClass(String className) throws ClassNotFoundException{
          byte[] data = classData(className);
          if(data == null)
               return getParent().loadClass(className);
          else
               return defineClass(className,data,0, data.length);
}Create an instance, Add directories and/or jar files with addFile then loadClass the class you want.

Similar Messages

  • How to use class.forName

    I am trying to use Class.forName() from a string which is passed to me as argument.
    Class batchClass = Class.forName(args[1]);
    A jar file contains the class file for the string received above and I have this jar file in the manifest of my executable jar.
    I get a class not found exception when I run my executable jar
    Can some body give pointers..what could possibly be the issue.
    The jar file is in my classpath
    run script
    #!/bin/csh
    java -jar -DDBPROVIDER=NO -DDBUS_ROOT=$DBUS_ROOT -DVTNAME=$VTNAME ./jar/IntraDayDepotPositionBatch.jar MagellanStart IntraDayDepotPositionBatch INPUTFILE LOGFILE
    Exception
    Magellan program starting - program class IntraDayDepotPositionBatch
    Cannot find program class - IntraDayDepotPositionBatch
    IntraDayDepotPositionBatch
    java.lang.ClassNotFoundException: IntraDayDepotPositionBatch
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at com.db.mmrepo.app.IntraDayDepotPositionBatch.MagellanStart.main(Unknown Source)
    Thanks for your time and feedback on this

    actually i tried both...with package name and without package name..
    nothing worked...
    my manifest file also contains the path to the package..so does the classpath

  • Why use Class.forName() ?

    Why is it always adviced to use Class.forName( nameOfTheDriver ). Why dont we simply import the driver via the import statement ?
    Please note that this topic is part of a bigger topic I published in Java programming about difficulties I had importing driver. See:
    http://forums.java.sun.com/thread.jsp?forum=31&thread=147534
    for more details.

    Because using an import statement only tells the compiler about the driver. Class.forName() actually loads the driver when the program runs, which is what you want to happen.

  • How to create an object of our own class by using Class.forName()??

    how to create an object of our own class by using Class.forName()??
    plzz anser my qustion soon..

    Class.forName does not create an object. It returns a reference to the Class object that describes the metadata for the class in question--what methods and fields it has, etc.
    To create an object--regardless of whether it's your class or some other class--you could call newInstance on the Class object returned from Class.forName, BUT only if that class has a no-arg constructor that you want to call.
    Class<MyClass> clazz = Class.forName("com.mycompany.MyClass");
    MyClass mine = clazz.newInstance();If you want to use a constructor that takes parameters, you'll have to use java.lang.reflect.Constructor.
    Google for java reflection tutorial for more details.
    BUT reflection is often abused, and often employe when not needed. Why is it that you think you need this?

  • Why can't i use class.forName(str) ?

    Heys all i have this piece of code which is working fine:
    *try {*
    java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    *} catch (java.lang.ClassNotFoundException e) {*
    now the problem is that i was under the impression that i could use class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); but it wouldn't compile. does anyone know why is this so?

    Class.forName() says "call the static method forName() that is defined in java.lang.Class". It returns a reference to an instance of java.lang.Class.
    SomeClass.class is known as a class literal. It is not a member, not a field, not a method. It evaluates to a reference to an instance of java.lang.Class.
    You cannot do class.something().
    Edited by: jverd on Oct 26, 2010 9:46 AM

  • Error When Using Class :(

    Hey,
    Class:
    package
        import flash.display.MovieClip;
        import flash.events.Event;
        public class Main extends MovieClip
            public var enemyA:Array = [];
            public var birdA:Array = [];
            public var rowNum:int = 2;
            private var gap:int = 100;
            private var obj_no = 2;
            public var enemy1:mychar = new mychar();
            public var TheBird:BirdChar = new BirdChar();
            public function Main()
                // constructor code
                createEnemyF();
                createBirdF();
                this.addEventListener(Event.ENTER_FRAME,loopF);
            public function createEnemyF()
                for (var i:int = 0; i < rowNum; i++)
                    for (var j:int = 0; j < obj_no; j++)
                        enemy1.x = Math.random() * stage.stageWidth - enemy1.width;
                        enemy1.y = - i * (gap + enemy1.height) - 30.65;
                        enemyA.push(enemy1);
                        addChild(enemy1);
            public function createBirdF() {
                TheBird.x = 270.95;
                TheBird.y = 350.95;
                birdA.push(TheBird);
                addChild(TheBird);
            public function loopF(event:Event) {
                updateEnemyPositionsF();
                updateBirdPositionsF();
                hitTestF();
            public function updateEnemyPositionsF() {
                enemy1.y +=  2;
            public function updateBirdPositionsF() {
                TheBird.x = mouseX;
            public function hitTestF() {
                if(TheBird.hitTestObject(enemy1))
                    gotoAndPlay(5);
                    trace('The Bird Hit Enemy 1');
    This conflicts and causes this error:
    1046: Type was not found or was not a compile-time constant: MouseEvent
    ^ ^ Code repeats to all of my event listeners
    Thanks for your time.

    Thanks, i thought it might be this because of previous problems but i seen i already had : import flash.events.Event; so i thought that would be OK!
    Second Error:
    1180: Call to an undefined method Timer.
    I think this is the same sort of thing but what to import to fix this?
    So far these are my imports:
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.events.TimerEvent;
    Thanks for helping.
    Date: Thu, 3 Nov 2011 05:36:22 -0600
    From: [email protected]
    To: [email protected]
    Subject: Error When Using Class
        Re: Error When Using Class
        created by markerline in Flash Pro - General - View the full discussion
    Looks like you imported events.Event but not events.MouseEvent (or some similar syntax) basically you must import MouseEvents separately from other Events.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4005227#4005227
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4005227#4005227. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Flash Pro - General by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Database connectivity without using Class.forName()

    Hi,
    Can anyone please tell how we can connect to a database without in java without using the Class.forName() method , and then how the database driver gets loaded.
    Regards,
    Tanmoy

    Hi,
    I recently wrote code that connects to a database without using Class.forName() in order to be compatible with Microsoft's JVM. I read about it here:
    http://www.idssoftware.com/faq-e.html#E1
    Basically, you create a new Driver object and use its connect method.
    Here's what my particular code ended up being:
    String url = "jdbc:mysql://localhost:3306/test?user=root&password=mypass";
    Driver drv = new org.gjt.mm.mysql.Driver();
    Connection con = drv.connect(url,null);

  • Instantiating object using Class.forName()

    What is the difference between instantiating using Class.forName() method and instantiating using the new operator?

    The difference is that you can use the new operator to instantiate an object, but you can't do it using Class.forName().
    But seriously folks...
    Presumably you're talking about Class.newInstance()--which often appears right on the heels of Class.forName().
    New gives you compile-time checks you don't get with Class.forName(). If it compiles with new, then you know the constructor in question exists on the class in question.
    With Class.newInstance() (and it's cousin (also called newInstance, I think) in the Constructor class), you can't be sure until you actually execute it whether that constructor even exists.
    New requires you to know the class at compile time. NewInstance lets you defer the specific class until runtime.
    New is simpler and more direct.
    (Did I just do your homwork for you? Hope not.)

  • Need Help Loading Sqlbase Driver Using Class.forName(...

    I'm having trouble connecting to a Sqlbase database on my PC. The problem seems to be with loading the driver with the "Class.forName" method. My source code (listed below) is in the "C:\My Documents\java" folder. I installed the Sqlbase driver in "C:\com\centurasoft\java\sqlbase" folder. The driver installation modified my autoexec.bat file to include the line "SET CLASSPATH=C:\com\centurasoft\java\sqlbase".
    The epdmo database is in a folder on my D:\ drive.
    It seems to find the SqlbaseDriver.class file, but for some reason it can't load it. I would greatly appreciate any suggestions as to how I can fix this.
    With the line -- Class.forName("centura.java.sqlbase.SqlbaseDriver");
    The SqlbaseEx.java program will compile, but I get the following error
    when I try to run it:
    Exception in thread "main" java.lang.NoClassDefFoundError: SqlbaseDriver (wrong name: com/centurasoft/java/sqlbase/SqlbaseDriver)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    ... [several more lines like these]
    at SqlbaseEx.main(SqlbaseEx.java:25)
    With the line -- DriverManager.registerDriver(new SqlbaseDriver());
    The SqlbaseEx.java program will NOT compile. I get the following error:
    SqlbaseEx.java:21: cannot access SqlbaseDriver
    bad class file: C:\com\centurasoft\java\sqlbase\SqlbaseDriver.class
    class file contains wrong class: com.centurasoft.java.sqlbase.SqlbaseDriver
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    Also, does the line -- String url = "jdbc:sqlbase:epdmo";
    look OK? I've seen numerous examples and they all have some values separated by slashes //. Am I
    missing something here that will bite me when I get past this driver loading error?
    import java.sql.*;
    // Create the ...
    public class SqlbaseEx {
    public static void main(String args[]) {
    String url = "jdbc:sqlbase:epdmo";
    Connection con;
    String createString;
    createString = "create table COFFEES " +
    "(COF_NAME varchar(32), " +
    "SUP_ID int, " +
    "PRICE float, " +
    "SALES int, " +
    "TOTAL int)";
    Statement stmt;
    try {
    Class.forName("centura.java.sqlbase.SqlbaseDriver");
    // DriverManager.registerDriver(new SqlbaseDriver());
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    try {
    con = DriverManager.getConnection(url, "SYSADM", "SYSADM");
    stmt = con.createStatement();
    stmt.executeUpdate(createString);
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());

    Thanks for the reply.
    Upon further testing, I think my original post was slightly incorrect: if I use either of the following lines --
    Class.forName("com.centurasoft.java.sqlbase.SqlbaseDriver");
    or
    Class.forName("centura.java.sqlbase.SqlbaseDriver");
    I get the following error at runtime:
    ClassNotFoundException: com.centurasoft.java.sqlbase.SqlbaseDriver
    or
    ClassNotFoundException: centura.java.sqlbase.SqlbaseDriver
    It is when I use the line -- Class.forName("SqlbaseDriver");
    that I get the long error message in my original post.
    I don't understand why it can't find/load the driver. I feel like I've covered all the bases -- I've tried numerous variations of the driver name in the Class.forName method, my classpath variable seems to be set correctly. Does it matter what folder I compile my program in? Right now, I've just been compiling it in the same folder as the driver file -- c:\com\centurasoft\java\sqlbase.

  • Creating Object using Class.forName vs new

    Hello,
    Is there any difference between:
    Class c = Class.forName("Foo");
    Foo foo = (Foo) c.newInstance();
    and
    Foo foo = new Foo();
    Thanks.

    Simple search brings this:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=614699

  • ClassNotFoundException when using InitialContextFactoryImpl

    Dear Experts,
           I'm trying to access an EJB which has been deployed on SAP J2EE Engine from a J2SE client by following the guide Link: [Accessing Enterprise JavaBeans Using JNDI in SAP NetWeaver Application Server|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/605ff5f2-e589-2910-3ead-e558376e6f3d].
           When the program lauch to Context ctx = new InitialContext(props);
           A ClassNotFoundException is throw out.
           I found the error is caused by the property entry:
    props.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sap.engine.services.jndi.InitialContextFactoryImpl");
           So which JAR file contains the InitialContextFactoryImpl class? How can I solve this problem?
    I copied my code as follow, hope you can help me.
            Properties props = new Properties();
             props.put(Context.INITIAL_CONTEXT_FACTORY,
                  "com.sap.engine.services.jndi.InitialContextFactoryImpl");
             props.put(Context.PROVIDER_URL, "localhost:50004");
             props.put(Context.SECURITY_PRINCIPAL, "administrator");
             props.put(Context.SECURITY_CREDENTIALS, "abcd1234");
             try{
                  Context ctx = new InitialContext(props);
                  Object o = ctx.lookup(
                            "sap.com/CartEAR/REMOTE/CartBean/cart.ejb.CartRemote");
                  cartRemote = (CartRemote) PortableRemoteObject.narrow(o, CartRemote.class);

    Hi YiNing,
    I assume you're working with a CE 7.1 version. In this case, please refer to this [article|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/605ff5f2-e589-2910-3ead-e558376e6f3d]. And for the lookup string, even better check the new [EJB Lookup Scheme|http://help.sap.com/saphelp_nwce10/helpdata/en/45/e692b2cfaa5591e10000000a1553f7/frameset.htm].
    HTH!
    -- Vladimir

  • Question about static context when using classes

    hey there.
    i'm pretty new to java an here's my problem:
    public class kreise {
         public static void main (String[] args) {
             //creating the circles
             create a = new create(1,4,3);
             create b = new create(7,2,5);
             System.out.println(a);
             System.out.println(b);
             //diameters...unimportant right now
             getDiameter a_ = new getDiameter(a.radius);
             getDiameter b_ = new getDiameter(b.radius);
             System.out.println(a_);
             System.out.println(b_);
             //moving the circles
             double x = 2;
             double y = 9;
             double z = 3;
             a = create.move();
             System.out.println(a);
    }creating a circle makes use of the class create which looks like this:
    public class create {
        public double k1;
        public double k2;
        public double radius;
        public create(double x,double y,double r) {
            k1 = x;
            k2 = y;
            radius = r;
        public create move() {
            k1 = 1;
            k2 = 1;
            radius = 3;
            return new create (k1,k2,radius);
        public String toString() {
        return "Koordinaten: "+k1+" / "+k2+". Radius: "+radius;
    }now that's all totally fine, but when i try to usw create.move to change the circles coordinates the compiler says that the non-static method move() can't be referenced from a static context. so far i've seen that my main() funktion MUST be static. when declaring the doubles k1, k2, and radius in create() static it works, but then of course when having created the second circle it overwrites the first one.
    i pretty much have the feeling this is very much a standard beginner problem, but searching for the topic never really brought up my problem exactly. thanks in advance!

    You can't access a non-static method from within a static context. So, you have to call move() from outside of the main method. main has to be static because, in short, at least one method has to be static because there haven't been any objects initialized when the program is started. There are more fundamental problems than with just the static context issue.
    I'm confused by your code though. You call create.move(), but this would only be possible if move() was static, and from what I see, it's not. Now that's just one part of it. My second issue is that the logic behind the move() method is very messy. You shouldn't return a newly instantiated object, instead it should just change the fields of the current object. Also as a general rule, instance fields should be private; you have them as public, and this would be problematic because anything can access it.
    Have you heard of getters and setters? That would be what I recommend.
    Now, also, when you are "moving" it, you are basically creating a new circle with completely differently properties; in light of this, I've renamed it change(). Here would be my version of your code:
    public class CircleTester {
        public static void main (String[] args)
             //Bad way to do it, but here's one way around it:
             new CircleTester().moveCircle();
        private void moveCircle()     //really a bad method, but for now, it'll do
            Circle a = new Circle(1,4,3);
            Circle b = new Circle(7,2,5);
            System.out.println(a);
            System.out.println(b);
            //diameters. Don't need to have a new getDiameter class
            double a_ = a.getRadius() * 2;     //Instead of doing * 2 each time, you could have a method that just returns the radius * 2
            double b_ = b.getRadius() * 2;
            System.out.println(a_);
            System.out.println(b_);
            //move the circle
            a.change(2,9,3);
            System.out.println(a);
    public class Circle {
        private double k1;
        private double k2;
        private double radius;
        public Circle(double x,double y,double r)
            k1 = x;
            k2 = y;
            radius = r;
        public void change(int x, int y, int r)
            k1 = x;
            k2 = y;
            radius = r;
        public String toString()
             return "Koordinaten: "+k1+" / "+k2+". Radius: "+radius;
        public double getRadius()
             return radius;
    }On another note, there is already a ellipse class: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/geom/Ellipse2D.html

  • Top of List event when using class cl_salv_hierseq_table

    Hi all,
      I am using above class to display Top of List .
    I am to able to display one line at top using following :
    gr_hierseq->set_top_of_list( lr_content ).
    But i have to display 5 lines in top of list.
    Please let me know how can this be achieved.
    Thanks and Regards,
    Taranam

    Wow, that example did suck.  Sorry for that.  I have spent a little time revising the example program into such a form that you can easily see what you need to do.  SO here it is, hope it helps.   Pay close attention to the implementation of the on_top_of_page event handler method.
    REPORT zsalv_demo_hierseq_form_events NO STANDARD PAGE HEADING.
    TYPES: BEGIN OF g_type_s_master.
    INCLUDE TYPE alv_chck.
    TYPES:   expand   TYPE char01,
           END OF g_type_s_master,
           BEGIN OF g_type_s_slave.
    INCLUDE TYPE alv_t_t2.
    TYPES: END   OF g_type_s_slave.
    TYPES: BEGIN OF g_type_s_test,
             amount      TYPE i,
             repid       TYPE syrepid,
             top_of_list TYPE i,
             end_of_list TYPE i,
           END OF g_type_s_test.
    CONSTANTS: con_master TYPE lvc_fname VALUE 'ALV_CHCK',
               con_slave  TYPE lvc_fname VALUE 'ALV_T_T2'.
    *... §5 Definition is later
    CLASS lcl_handle_events_hierseq DEFINITION DEFERRED.
    DATA: gs_test TYPE g_type_s_test.
    DATA: gt_master TYPE STANDARD TABLE OF g_type_s_master,
          gt_slave  TYPE STANDARD TABLE OF alv_t_t2.
    DATA: gr_hierseq TYPE REF TO cl_salv_hierseq_table.
    *... §5 object for handling the events of cl_salv_table
    DATA: gr_events_hierseq TYPE REF TO lcl_handle_events_hierseq.
    *       CLASS lcl_handle_events DEFINITION
    CLASS lcl_handle_events_hierseq DEFINITION.
      PUBLIC SECTION.
        METHODS:
          on_top_of_page FOR EVENT top_of_page OF cl_salv_events_hierseq
            IMPORTING r_top_of_page page table_index.
    ENDCLASS.                    "lcl_handle_events DEFINITION
    *       CLASS lcl_handle_events IMPLEMENTATION
    CLASS lcl_handle_events_hierseq IMPLEMENTATION.
      METHOD on_top_of_page.
        DATA: lr_content TYPE REF TO cl_salv_form_element.
        DATA: lr_grid   TYPE REF TO cl_salv_form_layout_grid,
               lr_grid_1 TYPE REF TO cl_salv_form_layout_grid,
               lr_grid_2 TYPE REF TO cl_salv_form_layout_grid,
               lr_label  TYPE REF TO cl_salv_form_label,
               lr_text   TYPE REF TO cl_salv_form_text,
               l_text    TYPE string.
    *... create a grid
        CREATE OBJECT lr_grid.
    *... in the cell [1,1] create header information
        CONCATENATE 'TOP_OF_PAGE' text-h01 INTO l_text SEPARATED BY space.
        lr_grid->create_header_information(
          row    = 1
          column = 1
          text    = l_text
          tooltip = l_text ).
    *... add a row to the grid -> row 2
        lr_grid->add_row( ).
    *... in the cell [3,1] create a grid
        lr_grid_1 = lr_grid->create_grid(
                      row    = 3
                      column = 1 ).
    *... in the cell [1,1] of the second grid create a label
        lr_label = lr_grid_1->create_label(
          row     = 1
          column  = 1
          text    = 'Number of Records'
          tooltip = 'Number of Records' ).
    *... in the cell [1,2] of the second grid create a text
        lr_text = lr_grid_1->create_text(
          row     = 1
          column  = 2
          text    = gs_test-amount
          tooltip = gs_test-amount ).
        lr_label->set_label_for( lr_text ).
    *... in the cell [2,1] of the second grid create a label
        lr_label = lr_grid_1->create_label(
          row    = 2
          column = 1
          text    = 'Output Tool'
          tooltip = 'Output Tool' ).
    *... in the cell [2,2] of the second grid create a text
        lr_text = lr_grid_1->create_text(
          row    = 2
          column = 2
          text    = 'Seq List'
          tooltip = 'Seq List').
        lr_label->set_label_for( lr_text ).
    *... in the cell [2,1] of the second grid create a label
        lr_label = lr_grid_1->create_label(
          row    = 3
          column = 1
          text    = 'Another Label'
          tooltip = 'Another Label' ).
    *... in the cell [2,2] of the second grid create a text
        l_text = text-t15.
        lr_text = lr_grid_1->create_text(
          row    = 3
          column = 2
          text    = 'Another Text'
          tooltip = 'Another Text').
        lr_label->set_label_for( lr_text ).
    *... content is the top grid
        lr_content = lr_grid.
    *... set the content
        r_top_of_page->set_content( lr_content ).
      ENDMETHOD.                    "on_top_of_page
    ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
    * SELECTION-SCREEN                                                     *
    SELECTION-SCREEN BEGIN OF BLOCK gen WITH FRAME.
    PARAMETERS:
    p_amount TYPE i DEFAULT 30.
    SELECTION-SCREEN END OF BLOCK gen.
    * START-OF-SELECTION                                                   *
    START-OF-SELECTION.
      gs_test-amount = p_amount.
      gs_test-repid = sy-repid.
    *... §1 select data into global output table
      PERFORM select_data.
    * END-OF-SELECTION                                                     *
    END-OF-SELECTION.
      PERFORM display_hierseq.
    *&      Form  select_data
    * §1 select data into your global output table
    FORM select_data.
      FIELD-SYMBOLS: <ls_master> TYPE g_type_s_master.
      DATA: lt_slave TYPE STANDARD TABLE OF g_type_s_slave.
      SELECT * FROM (con_master)
        INTO CORRESPONDING FIELDS OF TABLE gt_master
        UP TO gs_test-amount ROWS.                              "#EC *
      LOOP AT gt_master ASSIGNING <ls_master>.
        SELECT * FROM (con_slave) INTO CORRESPONDING FIELDS
                   OF TABLE lt_slave
                   UP TO gs_test-amount ROWS
                   WHERE carrid EQ <ls_master>-carrid
                     AND connid EQ <ls_master>-connid.          "#EC *
        APPEND LINES OF lt_slave TO gt_slave.
      ENDLOOP.
    ENDFORM.                    " select_data
    *&      Form  display_hierseq
    *       text
    FORM display_hierseq.
      DATA:lt_binding TYPE salv_t_hierseq_binding,
           ls_binding TYPE salv_s_hierseq_binding.
      DATA:lr_functions TYPE REF TO cl_salv_functions_list.
      DATA:lr_columns TYPE REF TO cl_salv_columns_hierseq,
           lr_column  TYPE REF TO cl_salv_column_hierseq.
      DATA:lr_level TYPE REF TO cl_salv_hierseq_level.
    *... create the binding information between master and slave
      ls_binding-master = 'MANDT'.
      ls_binding-slave  = 'MANDT'.
      APPEND ls_binding TO lt_binding.
      ls_binding-master = 'CARRID'.
      ls_binding-slave  = 'CARRID'.
      APPEND ls_binding TO lt_binding.
      ls_binding-master = 'CONNID'.
      ls_binding-slave  = 'CONNID'.
      APPEND ls_binding TO lt_binding.
    *... §2 create an ALV hierseq table
      TRY.
          cl_salv_hierseq_table=>factory(
            EXPORTING
              t_binding_level1_level2 = lt_binding
            IMPORTING
              r_hierseq               = gr_hierseq
            CHANGING
              t_table_level1           = gt_master
              t_table_level2           = gt_slave ).
        CATCH cx_salv_data_error cx_salv_not_found.
      ENDTRY.
    *... Functions
    *... activate ALV generic Functions
      lr_functions = gr_hierseq->get_functions( ).
      lr_functions->set_all( abap_true ).
    *... *** MASTER Settings ***
      TRY.
          lr_columns = gr_hierseq->get_columns( 1 ).
        CATCH cx_salv_not_found.
      ENDTRY.
    *... set the columns technical
      TRY.
          lr_column ?= lr_columns->get_column( 'MANDT' ).
          lr_column->set_technical( if_salv_c_bool_sap=>true ).
        CATCH cx_salv_not_found.                            "#EC NO_HANDLER
      ENDTRY.
    *... set expand column
      TRY.
          lr_columns->set_expand_column( 'EXPAND' ).
        CATCH cx_salv_data_error.                           "#EC NO_HANDLER
      ENDTRY.
    *... set items expanded
      TRY.
          lr_level = gr_hierseq->get_level( 1 ).
        CATCH cx_salv_not_found.
      ENDTRY.
      lr_level->set_items_expanded( ).
    *... *** GENERAL Settings ***
    *... register to the events for top-of-page and end-of-page
      DATA: lr_events TYPE REF TO cl_salv_events_hierseq.
      lr_events = gr_hierseq->get_event( ).
      CREATE OBJECT gr_events_hierseq.
      SET HANDLER gr_events_hierseq->on_top_of_page FOR lr_events.
    *... display the table
      gr_hierseq->display( ).
    ENDFORM.                    "display_hierseq
    REgards,
    RIch Heilman

  • Error when using class wire in flat sequence

    I tried a search and didn't find anything on this.  I have a VI that I was going evaluate its execution time.  So to be quick about it, I encased the code in a flat sequence box and added a second frame, place a Get Date/Time in seconds in each and found the difference.  When I did this, my program had errors.  It appears that I have to wire the class inputs and output outside of the sequence structure or an error is generated.
    VI is reentrant although I doubt that makes a difference.
    I get the following error:
    Terminal: One or more of the inputs to this tunnel or shift register does not orginate at the dynamic input front panel terminal
    Error case:
    Error is fixed
    Does this seem like expected behavior?
    Randall Pursley

    I would not say it is "expected" behavior but quite possibly it is very correct behavior  (Read as "almost certainly").
    "Wrap-your-head-in-duct-tape" and read message 12 of this thread carefully. Dynamic terminals that are on the connector pane determine which DD vi is actually called at run time.  Unless those terminals are on the root diagram there is a chance they could be conditionally read or even in dead code (imagine the sequence frame was replaced by a case structure since all structures are treated as "structures")  this breaks "inplaceness" and if not resolved, by placeing the terminals on the root diagram, LabVIEW would need to determine at run time wether or not a buffer allocation was required.  Thats not really possible.
    Perhaps R&D will explain it in greater detail?  But, the way to avoid this error is to pay attention to terminal that are on the con pane and alwasy keep them on the root diagram (It's more effecient code in any case).
    Secondly, the first get date time should be moved outside the sequence and wired through frame 1 to force it to execute before any othe code in the frame. 
    Jeff

  • Intermittent ClassNotFoundException when using the Attach API

    I'm trying to load an agent dynamically and I'm getting occasional an occasional CNFE. It doesn't make any sense because I'll run once and it'll work. Then I'll turn around and run the same scenario and it fails. In both instances I KNOW that the class is indeed in the classpath. Any ideas what I may want to look at?
    Thanks,
    Rick

    curtisr7 wrote:
    I would expect a missing parent class, or an exception from a static block happen every time.
    Nope. For example if a static block was attempting a socket connection and the timing on that was bordeline such that timeouts occurred sometimes and not others.
    Or it reads a file. And something intermittently messes up the format of the file.
    I'm running a single threaded application(so this isn't a threading issue) that fails every 3-4 runs. Any other ideas?You are not running the Sun VM then. It always has multiple threads.

Maybe you are looking for

  • Adding header in report

    Hi Experts, could you please tell me how i can add one header statemntlike this in my report. ABC COMPANY Date-current date Regards Rajat

  • Code (not sql) injection by hackers via coldfusion

    Does anyone have any information on how hackers might inject code into my coldfusion files.  I am having a problem with hackers installing javascript links to their trojans inside the actual pages of my site.  I run the server with many different sit

  • How to change date format in query

    Hi all! there is Date field in query (ref to 0Date) and it is in "01.2010" format. Anybody knows how to switch to "Jan 2010" format?

  • Assigning a diff source system

    I have an infopackage which takes data from SQL server. Now I want to change it to a flat file. But the datasource,TR and Update rules remains same. Just the source system is going to be diff: Whats the best way and steps to acheive this.........

  • Items disappear off dashboard after a few seconds

    Hi everyone, I recently upgraded to 10.4.11 and ever since my dashboard has died. When I press F12 the screen greys but all dashboard items are gone. So I proceed to click on the "plus" and discover that when I drag widgets on to the dashboard they a