Call ejb from another class?

there are some codes form someone I dont understand, can anyone help me out ?
the class Call will run on the same VM as the CMP entity bean Subscriber. what I am not sure is the call in method f2() , i.e. s.setName() will really wirte data to databank, since the lookup was done in getScriber(), and not visible in f2()!
Am I right ?
public class Call {
pubic void f1(){
Context jndiContext = new InitialContext();
public void f2 (){
Subscriber s = getSubscriber(); // 1
s.setName(); // 2
private Subscriber getSubscriber(){
SubscriberHome sHome = (Subscriber)jndiLookup("SubscriberEJB"); // 3
Subscriber sb = sHome.fineByPrimaryKey(1);
}

call in method f2() , i.e. s.setName() will really
wirte data to databank, since the lookup was done in
getScriber(), and not visible in f2()!Can't say this for sure, unless I have a look into the setName() method. It doesn't seem to be taking any argument, and that's certainly not the same as setName(String name). It might be actually doing something meaningful. Better take a closer look.
public class Call {
pubic void f1(){
Context jndiContext = new InitialContext();
public void f2 (){
Subscriber s = getSubscriber(); // 1
s.setName(); // 2
private Subscriber getSubscriber(){
SubscriberHome sHome =
(Subscriber)jndiLookup("SubscriberEJB"); // 3
Subscriber sb = sHome.fineByPrimaryKey(1);
}Rich.

Similar Messages

  • Is it possible to call methods from another class from within an abstract c

    Is it possible to call methods from another class from within an abstract class ?

    I found an example in teh JDK 131 JFC that may help you. I t is using swing interface and JTable
    If you can not use Swing, then you may want to do digging or try out with the idea presented here in example 3
    Notice that one should refine the abstract table model and you may want to create a method for something like
    public Object getValuesAtRow(int row) { return data[row;}
    to give the desired row and leave the method for
    getValuesAt alone for getting valued of particaular row and column.
    So Once you got the seelcted row index, idxSelctd, from your table
    you can get the row or set the row in your table model
    public TableExample3() {
    JFrame frame = new JFrame("Table");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}});
    // Take the dummy data from SwingSet.
    final String[] names = {"First Name", "Last Name", "Favorite Color",
    "Favorite Number", "Vegetarian"};
    final Object[][] data = {
         {"Mark", "Andrews", "Red", new Integer(2), new Boolean(true)},
         {"Tom", "Ball", "Blue", new Integer(99), new Boolean(false)},
         {"Alan", "Chung", "Green", new Integer(838), new Boolean(false)},
         {"Jeff", "Dinkins", "Turquois", new Integer(8), new Boolean(true)},
         {"Amy", "Fowler", "Yellow", new Integer(3), new Boolean(false)},
         {"Brian", "Gerhold", "Green", new Integer(0), new Boolean(false)},
         {"James", "Gosling", "Pink", new Integer(21), new Boolean(false)},
         {"David", "Karlton", "Red", new Integer(1), new Boolean(false)},
         {"Dave", "Kloba", "Yellow", new Integer(14), new Boolean(false)},
         {"Peter", "Korn", "Purple", new Integer(12), new Boolean(false)},
         {"Phil", "Milne", "Purple", new Integer(3), new Boolean(false)},
         {"Dave", "Moore", "Green", new Integer(88), new Boolean(false)},
         {"Hans", "Muller", "Maroon", new Integer(5), new Boolean(false)},
         {"Rick", "Levenson", "Blue", new Integer(2), new Boolean(false)},
         {"Tim", "Prinzing", "Blue", new Integer(22), new Boolean(false)},
         {"Chester", "Rose", "Black", new Integer(0), new Boolean(false)},
         {"Ray", "Ryan", "Gray", new Integer(77), new Boolean(false)},
         {"Georges", "Saab", "Red", new Integer(4), new Boolean(false)},
         {"Willie", "Walker", "Phthalo Blue", new Integer(4), new Boolean(false)},
         {"Kathy", "Walrath", "Blue", new Integer(8), new Boolean(false)},
         {"Arnaud", "Weber", "Green", new Integer(44), new Boolean(false)}
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {
    // These methods always need to be implemented.
    public int getColumnCount() { return names.length; }
    public int getRowCount() { return data.length;}
    public Object getValueAt(int row, int col) {return data[row][col];}
    // The default implementations of these methods in
    // AbstractTableModel would work, but we can refine them.
    public String getColumnName(int column) {return names[column];}
    public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
    public boolean isCellEditable(int row, int col) {return (col==4);}
    public void setValueAt(Object aValue, int row, int column) {
    data[row][column] = aValue;
    };

  • Calling EJB from another EJB

    I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
    the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
    practice ?? If not, do I need to get remote reference of the EJB2 every time I
    need to call EJB2 method??
    Thanks in advance.

    To refer a Ejb from another Ejb include <ejb-ref> in ejb-jar.xml
    <session>
    <ejb-name>Ejb1</ejb-name>
    <ejb-ref>
    <ejb-ref-name>Ejb2</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>com.ejb.Ejb2Home</home>
    <remote>com.ejb.Ejb2</remote>
    </ejb-ref>
    <session>
    Include a <reference-discriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>EjbSession</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>Ejb2</ejb-ref-name>
    <jndi-name>com.ejb.Ejb2Home</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    In Ejb1 bean class refer to Ejb2 method with a remote reference to Ejb2.
    InitialContext initialContext = new InitialContext();
    Ejb2Home ejb2Home = (Ejb2Home)initialContext.lookup("com.ejb.Ejb2Home");
    Ejb2 ejb2 = ejb2Home.findByPrimaryKey();
    Alex Pratt wrote:
    I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
    the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
    practice ?? If not, do I need to get remote reference of the EJB2 every time I
    need to call EJB2 method??
    Thanks in advance.

  • Calling method from another class problem

    hi,
    i am having problem with my code. When i call the method from the other class, it does not function correctly?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Dice extends JComponent
        private static final int SPOT_DIAM = 9; 
        private int faceValue;   
        public Dice()
            setPreferredSize(new Dimension(60,60));
            roll(); 
        public int roll()
            int val = (int)(6*Math.random() + 1);  
            setValue(val);
            return val;
        public int getValue()
            return faceValue;
        public void setValue(int spots)
            faceValue = spots;
            repaint();   
        @Override public void paintComponent(Graphics g) {
            int w = getWidth(); 
            int h = getHeight();
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.WHITE);
            g2.fillRect(0, 0, w, h);
            g2.setColor(Color.BLACK);
            g2.drawRect(0, 0, w-1, h-1); 
            switch (faceValue)
                case 1:
                    drawSpot(g2, w/2, h/2);
                    break;
                case 3:
                    drawSpot(g2, w/2, h/2);
                case 2:
                    drawSpot(g2, w/4, h/4);
                    drawSpot(g2, 3*w/4, 3*h/4);
                    break;
                case 5:
                    drawSpot(g2, w/2, h/2);
                case 4:
                    drawSpot(g2, w/4, h/4);
                    drawSpot(g2, 3*w/4, 3*h/4);
                    drawSpot(g2, 3*w/4, h/4);
                    drawSpot(g2, w/4, 3*h/4);
                    break;
                case 6:
                    drawSpot(g2, w/4, h/4);
                    drawSpot(g2, 3*w/4, 3*h/4);
                    drawSpot(g2, 3*w/4, h/4);
                    drawSpot(g2, w/4, 3*h/4);
                    drawSpot(g2, w/4, h/2);
                    drawSpot(g2, 3*w/4, h/2);
                    break;
        private void drawSpot(Graphics2D g2, int x, int y)
            g2.fillOval(x-SPOT_DIAM/2, y-SPOT_DIAM/2, SPOT_DIAM, SPOT_DIAM);
    }in another class A (the main class where i run everything) i created a new instance of dice and added it onto a JPanel.Also a JButton is created called roll, which i added a actionListener.........rollButton.addActionListener(B); (B is instance of class B)
    In Class B in implements actionlistener and when the roll button is clicked it should call "roll()" from Dice class
    Dice d = new Dice();
    d.roll();
    it works but it does not repaint the graphics for the dice? the roll method will get a random number but then it will call the method to repaint()???
    Edited by: AceOfSpades on Mar 5, 2008 2:41 PM
    Edited by: AceOfSpades on Mar 5, 2008 2:42 PM

    One way:
    class Flintstone
        private String name;
        public Flintstone(String name)
            this.name = name;
        public String toString()
            return name;
        public static void useFlintstoneWithReference(Flintstone fu2)
            System.out.println(fu2);
        public static void useFlintstoneWithOutReference()
            Flintstone barney = new Flintstone("Barney");
            System.out.println(barney);
        public static void main(String[] args)
            Flintstone fred = new Flintstone("Fred");
            useFlintstoneWithReference(fred); // fred's the reference I"m passing to the method
            useFlintstoneWithOutReference();
    {code}
    can also be done with action listener
    {code}    private class MyActionListener implements ActionListener
            private Flintstone flintstone;
            public MyActionListener(Flintstone flintstone)
                this.flintstone = flintstone;
            public void actionPerformed(ActionEvent arg0)
                //do whatever using flinstone
                System.out.println(flintstone);
        }{code}
    Edited by: Encephalopathic on Mar 5, 2008 3:06 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Call method from another class instance

    Forgive me if I don't make sense, I'm relatively new to Java and still not up on all the lingo.
    So here's what I want to do... This is probably easier explained with code:
    ParentClass.java
    public class ParentClass {
         public static void main(String[] args)
              ChildClass1 child1 = new ChildClass1();
              ChildClass2 child2 = new ChildClass2();
              System.out.println("ParentClass");
              System.out.println(child1.getText());
              System.out.println(child2.getText());
    ChildClass1.javapublic class ChildClass1 {
         private String text = "ChildClass1";
         public ChildClass1()
              System.out.println("ChildClass1 Constructor");
         public String getText()
         { return text; }
    }ChildClass2.java is identical to ChildClass1, except the 1's replaced with 2's etc.
    I need to be able to call getText() in ChildClass1 from ChildClass2, and eventually methods in the ParentClass class.
    As I understand, if I make the ChildClass's extend the ParentClass, every new instance of the ChildClass will create a new instance of the ParentClass. What I need though, is one instance of ParentClass with it's eventual variables etc. set, and then have the two classes defined within, able to talk to each other and the methods in the ParentClass.
    How does one go about doing this? Does that even make sense?
    Thanks, Savage

    You may need to read thru the information provided on this page to understand how to create objects: http://java.sun.com/docs/books/tutorial/java/data/objectcreation.html
    I'd also suggest you read the tutorial available at: http://java.sun.com/docs/books/tutorial/java/index.html
    Regarding how you call a method belonging to another class you could do it in the foll. ways depending on whether the method is static or not - a static method may be called using the class name followed by a dot and the static method name while a non-static method would require you to create an instance of the class and then use that instance name followed by a dot and the method name. All said and done i'd still suggest you read thru the complete Java programming tutorial to get a good grounding on all these concepts and fundamentals of the language if you are looking to master the technology.
    Thanks
    John Morrison

  • Calling arraylist from another class - help please!!

    Hey, I need some help calling my arraylist from my GUI class, as the arraylist is in the 'AlbumList' class and not in the 'GUI' class i get the error 'cannot find symbol', which is pretty obvious but i cannot figure how to get around this problem. help would be greatly appreciated.
    i have written ***PROBLEM*** next to the bad line of code!
    Thanks!!
    public class Album
        String artist;
        String title;
        String genre;
        public Album(String a, String t, String g)
            artist = a;
         title = t;
            genre = g;
         public String getArtist()
            return artist;
        public String getTitle()
            return title;
         public String getGenre()
            return genre;
    public class AlbumList
        public ArrayList <Album> theAlbums;
        int pointer = -1;
        public AlbumList()
            theAlbums = new ArrayList <Album>();
        public void addAlbum(Album newAlbum)
         theAlbums.add(newAlbum);
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GUI extends JFrame
        public int max = 5;
        public int numAlbums = 4;
        public int pointer = -1;
        public GUI ()
            super("Recording System");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel main = new JPanel();
            JPanel panel1 = new JPanel();
            panel1.setLayout(new GridLayout(3,2,0,0));
            JPanel panel2 = new JPanel();
            panel2.setLayout(new GridLayout(1,2,20,0));
            final JLabel artistLBL = new JLabel("Artist: ");
            final JLabel titleLBL = new JLabel("Title: ");
            final JLabel genreLBL = new JLabel("Genre: ");
            final JTextField artistFLD = new JTextField(20);
            final JTextField titleFLD = new JTextField(20);
            final JTextField genreFLD = new JTextField(20);
            final JButton nextBTN = new JButton("Next");
            nextBTN.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    pointer++;
                    artistFLD.setText(theAlbums.get(pointer).getArtist());       ***PROBLEM***
                    titleFLD.setText("NEXT");
                    genreFLD.setText("NEXT");
            final JButton prevBTN = new JButton("Prev");
            prevBTN.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    pointer--;
                    artistFLD.setText("PREVIOUS");
                    titleFLD.setText("PREVIOUS");
                    genreFLD.setText("PREVIOUS");
         panel1.add(artistLBL);
            panel1.add(artistFLD);
            panel1.add(titleLBL);
            panel1.add(titleFLD);
            panel1.add(genreLBL);
            panel1.add(genreFLD);
            panel2.add(prevBTN);
            panel2.add(nextBTN);
            main.add(panel1);
            main.add(panel2);
            setVisible(true);
            this.getContentPane().add(main);
            setSize(500, 500);
    -----------------------------------------------------------------------Thanks!!
    Edited by: phreeck on Nov 3, 2007 8:55 PM

    thanks, it dosnt give me a complication error but when i press the button it says out of bounds error, and i think my arraylist may be empty possibly even though i put this data in.. this is my test file which runs it all.
    any ideas? thanks!!
    public class Test
        public static void main(String []args)
            AlbumList a = new AlbumList();
            String aArtist = "IronMaiden";
            String aTitle = "7thSon";
            String aGenre = "HeavyMetal";
            Album newA = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newA);
            aArtist = "LambOfGod";
            aTitle = "Sacrament";
            aGenre = "Metal";
            Album newB = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newB);
            aArtist = "JohnMayer";
            aTitle = "Continuum";
            aGenre = "Guitar";
            Album newC = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newC);
            aArtist = "StillRemains";
            aTitle = "TheSerpent";
            aGenre = "Metal";
            Album newD = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newD);
         GUI tester = new GUI();
    }

  • Calling method from another class

    Got the below code for the Bank class with a log in system, Want i need is a While loop for
    "While ValidUser = True, Do method in Accounts class."
    package bank;
    import javax.swing.*;
    import java.lang.*;
    public class Bank {
                  /*User Arrays */
        public  String Customer[]= new String[4];
        public  String Pin[] = new String[4];
                 /* User Tryed details */
            String User;
          String PinAuth;
    Boolean ValidUser;
    public Bank ()
                  /*Customers */
              Customer[0]="John";
        Customer[1]="Alan";
        Customer[2]="Lisa";
        Customer[3]="Liam";
        Pin[0]="1234";
        Pin[1]="1982";
        Pin[2]="4321";
        Pin[3]="5678";
    public Bank(String CustAtt, String PinAtt)
         User = CustAtt;
         PinAuth = PinAtt;
    public String getUser()
        return User;
    public String getPin()
        return PinAuth;
    public void setUser(String CustAtt)
        User = CustAtt;
    public void setPin(String PinAtt)
        PinAuth = PinAtt;
      public static void main    (String args[] ){
    System.out.println("Welcome to The Bank of Scotland");
          String User;
          String PinAtt;
        boolean ValidUser;
          /* Get User Details */
         User =
                JOptionPane.showInputDialog("Please Enter Your Name");
        /* Get User pin */
         PinAtt =
                JOptionPane.showInputDialog("Enter your Pin");
    /* Print USer Details */
         System.out.println(User);
         System.out.println(PinAtt);
    /* Authorise Customer */
    Bank newBank = new Bank();
    for(int i=0; i<4;i++)
    if(User.equals(newBank.Customer) && PinAtt.equals(newBank.Pin[i]))
    ValidUser=true;
    else
    ValidUser=false;
    if(ValidUser=true)
    System.out.println("Auth");
    else if(ValidUser=false)
    System.out.println("Log in details are in correct");
    while(ValidUser=true)
    Account Class, in this class i need options for selecting withdraw deposit  and close account, not sure if i could do this in the Current account class though.
    Any advice will be great package bank;
    import javax.swing.*;
    import java.lang.*;
    public class Account {
    private String AccountNo;
    private int Balance;
    private int Deposit;
    String AccountUsed;
    public Account () {
    public String getAccountNo ()
    return AccountNo;
    public void setAccountNo (int val) {
    AccountUsed = AccountNo;
    public int getBalance () {
    return Balance;
    public void setBalance (int val) {
    this.Balance = val;
    public int getDeposit ()
    return Deposit;
    public void setDeposit (int val)
    this.Deposit = val;
    this.Balance=this.Balance+this.Deposit;
    public void setWithdrawl (int val)
    this.Balance=this.Balance-val;
    public static void account (String args[] ){
    String Deposit = new String();
    String Withdraw = new String() ;
    System.out.println("Deposit - Withdraw");
    Account newAccount = new Account();
    Deposit =
    JOptionPane.showInputDialog("Enter the ammount you wish to deposit");
    Withdraw =
    JOptionPane.showInputDialog("Enter the amount you wish to Withdraw");
    System.out.println(Deposit);
    System.out.println(Withdraw);
    Account custAccount =new Account();
    custAccount.setDeposit(Integer.parseInt(Deposit));
    custAccount.setWithdrawl(Integer.parseInt(Withdraw));
    System.out.println(custAccount.getBalance());

    Maxideon wrote:
    All of these are valid,
    while(validUser == true) {
    while(validUser) {
    //I prefer this one
    if(validUser == true) {
    if(validUser) {
    //I prefer this one
    } What you have,
    if(validUser = true) {
    if(validUser = false) {
    }is different. I have two equal signs, while you have one. What do you think one equal sign does?
    P.S. All your variable names are screwed up. They should begin with a lower case letter.
    Edit
    Some other anomalies: you declared ValidUser as a Boolean and you imported java.lang. .... Why?
    Edit
    Another weird thing.
    String Deposit = new String();
    String Withdraw = new String();?I Am fairly new to java, I have things "working" to an extent, and i am aware of the naming conventions over the variable names,

  • Using a class that has a main from another class

    Can I call a class that has a main from another classes public methods?

    Yes, you can, although strictly speaking you won't be calling that classes "main" method, you will simply be calling and initializing the class through it's constructor, the "main" method will be ignored. If you have code inside your main method that you want executed as well consider moving it inside your constructor and simply using the "main" method as an application initializer:
    public static void main( String args[] ) {
    new MyClass();
    This way you can use your class as an application or call it from another class and not have any duplicate code inside your "main" method and constructor. You can also take this further and have it call the applet initialization so that you can launch it any way you like, I suspect this is a bit beyond what you were asking.
    Does this solve your problem?

  • Calling EJB from class in same ear

    Has anyone ever attempted to call an EJB from a class that is in the same ear?
    I have a singleton class, not
    another EJB, that is trying to get ahold of an EJB to call a method. This method
    has been defined to have both
    a local and remote interface.
    I thought I should be able to get a hold of the local interface. When I try to
    get the interface out of JNDI
    as follows:
    PickupCpaLocalHome cpaHome = (PickupCpaLocalHome) ctx.lookup("pickup.PickupCpaEJBLocal");
    I get an exception:
    javax.naming.LinkException: [Root exception is
         javax.naming.NameNotFoundException: Unable to resolve
         'app/ejb/PickupCpaEJB.jar#PickupCpaEJB/local-home' Resolved: 'app/ejb'
         Unresolved:'PickupCpaEJB.jar#PickupCpaEJB' ; remaining name
         'PickupCpaEJB.jar#PickupCpaEJB/local-home']; Link Remaining Name:
    'java:app/ejb/PickupCpaEJB.jar#PickupCpaEJB/local-home'
    When I look at the JNDI tree using the WebLogic console, it shows that "pickup.PickupCpaEJBLocal"
    is
    in JNDI.
    Since the local interface doesn't work, I thought I'd try the remote interface.
    The remote interface
    works fine from my client and from another EJB in a different ear. Using the
    remote interface I get an
    exception when trying to cast the result to my home.
    java.lang.ClassCastException:
    com.fedex.pickup.j2ee.ejb.cpa.PickupCpaEJB_gapk5_HomeImpl_WLStub
    // Code
    PickupCpaHome cpaHome = (PickupCpaHome) ctx.lookup("pickup.PickupCpaEJBRemote");
    As I mentioned earlier, the same code works in a client and in an EJB in another
    ear.
    Any ideas

    Has anyone ever attempted to call an EJB from a class that is in the same ear?
    I have a singleton class, not
    another EJB, that is trying to get ahold of an EJB to call a method. This method
    has been defined to have both
    a local and remote interface.
    I thought I should be able to get a hold of the local interface. When I try to
    get the interface out of JNDI
    as follows:
    PickupCpaLocalHome cpaHome = (PickupCpaLocalHome) ctx.lookup("pickup.PickupCpaEJBLocal");
    I get an exception:
    javax.naming.LinkException: [Root exception is
         javax.naming.NameNotFoundException: Unable to resolve
         'app/ejb/PickupCpaEJB.jar#PickupCpaEJB/local-home' Resolved: 'app/ejb'
         Unresolved:'PickupCpaEJB.jar#PickupCpaEJB' ; remaining name
         'PickupCpaEJB.jar#PickupCpaEJB/local-home']; Link Remaining Name:
    'java:app/ejb/PickupCpaEJB.jar#PickupCpaEJB/local-home'
    When I look at the JNDI tree using the WebLogic console, it shows that "pickup.PickupCpaEJBLocal"
    is
    in JNDI.
    Since the local interface doesn't work, I thought I'd try the remote interface.
    The remote interface
    works fine from my client and from another EJB in a different ear. Using the
    remote interface I get an
    exception when trying to cast the result to my home.
    java.lang.ClassCastException:
    com.fedex.pickup.j2ee.ejb.cpa.PickupCpaEJB_gapk5_HomeImpl_WLStub
    // Code
    PickupCpaHome cpaHome = (PickupCpaHome) ctx.lookup("pickup.PickupCpaEJBRemote");
    As I mentioned earlier, the same code works in a client and in an EJB in another
    ear.
    Any ideas

  • Error in calling an EJB from another EJB

    Hello All,
    I have a scenario where i need to call a method of an ejb from another ejb.
    Both the EJB's are in different DC's.
    EG: DC1 using DC2
    I have added the public part of DC2 in DC1.
    The following code is written in DC1 to access the EJB of DC2
          MyRemote l_remote;
           MyHome l_home;
           InitialContext l_ctx = new InitialContext();
    >>       l_home = (MyHome)l_ctx.lookup("JNDI Name");
           l_remote = (MyRemote)l_home.create();
    There is no error at build time and deploy time, but at run time "MyHome" class is not found.
    Even i am not able to access the helper class defined in the DC2 at runtime.
    Please help.
    Thanks in Advance

    First off, wrong forum section.
    Check if your JNDI name is correctly placed for the bean you're calling -- check j2ee-engine.xml for that. Check the EJB container if the ear file you deployed is there and updated.
    Try placing  "localejbs/JNDI name" on your lookup parameter.
    Regards,
    Jan

  • Calling a method from another class... that requires variables?

    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
         cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), but I'm not sure how! I have tried, but then I get errors such as ')' expected?
    Any ideas! :D

    f1d wrote:
    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
    cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), seems that way from the error you posted
    but I'm not sure how!
    setDate(16, 6, 2008);
    I have tried, but then I get errors such as ')' expected?
    Any ideas! :Dyou need to post your code if you're getting specific errors like that.
    but typically ')' expected means just that, you have too many or not enough parenthesis (or in the wrong place, etc.)
    i.e. syntax error

  • Calling a TextFields get method from another class as a String

    This is my first post so be kind....
    I'm trying to create a login screen with Java Studio Creator. The Login.jsp has a Text Field for both the username and password. JSC automatically created get and set methods for these.
    public class Login extends AbstractPageBean
    private TextField usernameTF = new TextField();
    public TextField getUsernameTF() {
    return usernameTF;
    public void setUsernameTF(TextField tf) {
    this.usernameTF = tf;
    private PasswordField passwordTF = new PasswordField();
    public PasswordField getPasswordTF() {
    return passwordTF;
    public void setPasswordTF(PasswordField pf) {
    this.passwordTF = pf;
    My problem is in trying to call these methods from another class and return the value as a string.
    Any help on this matter would be greatly appreciated.

    the method returns the textfield, so you just need to get its text
    import java.awt.*;
    class Testing
      public Testing()
        Login login = new Login();
        System.out.println(login.getUsernameTF().getText());//<----
      public static void main(String[] args){new Testing();}
    class Login
    private TextField usernameTF = new TextField("Joe Blow");
    public TextField getUsernameTF() {
        return usernameTF;
    }

  • Calling a class's method from another class

    Hi, i would like to know if it's possible to call a Class's method and get it's return from another Class. This first Class doesn't extend the second. I've got a Choice on this first class and depending on what is selected, i want to draw a image on the second class witch is a Panel extended. I put the control "if" on the paint() method of the second class witch is called from the first by the repaint() (first_class.repaint()) on itemStateChanged(). Thankx 4 your help. I'm stuck with this.This program is for my postgraduation final project and i'm very late....

    import java.awt.*;
    import java.sql.*;
    * This type was generated by a SmartGuide.
    class Test extends Frame {
         private java.awt.Panel ivjComboPane = null;
         private java.awt.Panel ivjContentsPane = null;
         IvjEventHandler ivjEventHandler = new IvjEventHandler();
         private Combobox ivjCombobox1 = null;
    class IvjEventHandler implements java.awt.event.WindowListener {
              public void windowActivated(java.awt.event.WindowEvent e) {};
              public void windowClosed(java.awt.event.WindowEvent e) {};
              public void windowClosing(java.awt.event.WindowEvent e) {
                   if (e.getSource() == Test.this)
                        connEtoC1(e);
              public void windowDeactivated(java.awt.event.WindowEvent e) {};
              public void windowDeiconified(java.awt.event.WindowEvent e) {};
              public void windowIconified(java.awt.event.WindowEvent e) {};
              public void windowOpened(java.awt.event.WindowEvent e) {};
         private Panel ivjPanel1 = null;
    * Combo constructor comment.
    public Test() {
         super();
         initialize();
    * Combo constructor comment.
    * @param title java.lang.String
    public Test(String title) {
         super(title);
    * Insert the method's description here.
    * Creation date: (11/16/2001 7:48:51 PM)
    * @param s java.lang.String
    public void conexao(String s) {
         try {
              Class.forName("oracle.jdbc.driver.OracleDriver");
              String url = "jdbc:oracle:thin:system/[email protected]:1521:puc";
              Connection db = DriverManager.getConnection(url);
              //String sql_str = "SELECT * FROM referencia";
              Statement sq_stmt = db.createStatement();
              ResultSet rs = sq_stmt.executeQuery(s);
              ivjCombobox1.addItem("");
              while (rs.next()) {
                   String dt = rs.getString(1);
                   ivjCombobox1.addItem(dt);
              db.close();
         } catch (SQLException e) {
              System.out.println("Erro sql" + e);
         } catch (ClassNotFoundException cnf) {
    * connEtoC1: (Combo.window.windowClosing(java.awt.event.WindowEvent) --> Combo.dispose()V)
    * @param arg1 java.awt.event.WindowEvent
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void connEtoC1(java.awt.event.WindowEvent arg1) {
         try {
              // user code begin {1}
              // user code end
              this.dispose();
              // user code begin {2}
              // user code end
         } catch (java.lang.Throwable ivjExc) {
              // user code begin {3}
              // user code end
              handleException(ivjExc);
    * Return the Combobox1 property value.
    * @return Combobox
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private Combobox getCombobox1() {
         if (ivjCombobox1 == null) {
              try {
                   ivjCombobox1 = new Combobox();
                   ivjCombobox1.setName("Combobox1");
                   ivjCombobox1.setLocation(30, 30);
                   // user code begin {1}
                   this.conexao("select * from referencia");
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjCombobox1;
    * Return the ComboPane property value.
    * @return java.awt.Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.Panel getComboPane() {
         if (ivjComboPane == null) {
              try {
                   ivjComboPane = new java.awt.Panel();
                   ivjComboPane.setName("ComboPane");
                   ivjComboPane.setLayout(null);
                   getComboPane().add(getCombobox1(), getCombobox1().getName());
                   getComboPane().add(getPanel1(), getPanel1().getName());
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjComboPane;
    * Return the ContentsPane property value.
    * @return java.awt.Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.Panel getContentsPane() {
         if (ivjContentsPane == null) {
              try {
                   ivjContentsPane = new java.awt.Panel();
                   ivjContentsPane.setName("ContentsPane");
                   ivjContentsPane.setLayout(new java.awt.BorderLayout());
                   getContentsPane().add(getComboPane(), "Center");
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjContentsPane;
    * Return the Panel1 property value.
    * @return Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private Panel getPanel1() {
         if (ivjPanel1 == null) {
              try {
                   ivjPanel1 = new Panel();
                   ivjPanel1.setName("Panel1");
                   ivjPanel1.setBackground(java.awt.SystemColor.scrollbar);
                   ivjPanel1.setBounds(24, 118, 244, 154);
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjPanel1;
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initializes connections
    * @exception java.lang.Exception The exception description.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initConnections() throws java.lang.Exception {
         // user code begin {1}
         // user code end
         this.addWindowListener(ivjEventHandler);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Combo");
              setLayout(new java.awt.BorderLayout());
              setSize(460, 300);
              setTitle("Combo");
              add(getContentsPane(), "Center");
              initConnections();
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * Insert the method's description here.
    * Creation date: (11/17/2001 2:02:58 PM)
    * @return java.lang.String
    public String readCombo() {
         String dado = ivjCombobox1.getSelectedItem();
         return dado;
    * Starts the application.
    * @param args an array of command-line arguments
    public static void main(java.lang.String[] args) {
         try {
              /* Create the frame */
              Test aTest = new Test();
              /* Add a windowListener for the windowClosedEvent */
              aTest.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosed(java.awt.event.WindowEvent e) {
                        System.exit(0);
              aTest.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of Test");
              exception.printStackTrace(System.out);
    * Insert the type's description here.
    * Creation date: (11/17/2001 1:59:15 PM)
    * @author:
    class Combobox extends java.awt.Choice {
         public java.lang.String dado;
    * Combobox constructor comment.
    public Combobox() {
         super();
         initialize();
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Combobox");
              setSize(133, 23);
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * main entrypoint - starts the part when it is run as an application
    * @param args java.lang.String[]
    public static void main(java.lang.String[] args) {
         try {
              java.awt.Frame frame = new java.awt.Frame();
              Combobox aCombobox;
              aCombobox = new Combobox();
              frame.add("Center", aCombobox);
              frame.setSize(aCombobox.getSize());
              frame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
              frame.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of Combobox");
              exception.printStackTrace(System.out);
    * Insert the type's description here.
    * Creation date: (11/17/2001 2:16:11 PM)
    * @author:
    class Panel extends java.awt.Panel {
    * Panel constructor comment.
    public Panel() {
         super();
         initialize();
    * Panel constructor comment.
    * @param layout java.awt.LayoutManager
    public Panel(java.awt.LayoutManager layout) {
         super(layout);
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Panel");
              setLayout(null);
              setSize(260, 127);
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * main entrypoint - starts the part when it is run as an application
    * @param args java.lang.String[]
    public static void main(java.lang.String[] args) {
         try {
              java.awt.Frame frame = new java.awt.Frame();
              Panel aPanel;
              aPanel = new Panel();
              frame.add("Center", aPanel);
              frame.setSize(aPanel.getSize());
              frame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
              frame.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of java.awt.Panel");
              exception.printStackTrace(System.out);
    * Insert the method's description here.
    * Creation date: (11/17/2001 2:18:36 PM)
    public void paint(Graphics g) {
    /* Here's the error:
    C:\Test.java:389: non-static method readCombo() cannot be referenced from a static context
         System.out.println(Test.lerCombo());*/
         System.out.println(Test.readCombo());

  • ABAP Objects : calling one method from another class

    Hi,
    Can you please tell me how to call method from one class or interfce to another class.The scenario is
    I have one class CL_WORKFLOW_TASK, this class have interface IF_WORKFLOW_TASK & this interface have method IF_WORKFLOW_TASK~CLOSE. Now my requirement is ,
    There is another class CL_WORKFLOW_CHAIN ,this class have interface IF_WORKFLOW_CHAIN & this interface have method IF_WORKFLOW_CHAINCLOSE_ALL_PREDECESSORS. Now i have to write my code in this method but i have to use IF_WORKFLOW_TASKCLOSE method for closing the task.
    Can you please give me the code for the above .
    Please waiting for reply.

    Hi,
    You can use the concept of INHERITANCE  in this scenario.By using this concept, you can call all the public and protected  methods of class CL_WORKFLOW_TASK  in the required calss CL_WORKFLOW_CHAIN as per your requirement.
    Go through the  Introdctory(INHERITANCE) programming from this SAPHELP link.
    http://help.sap.com/saphelp_nw70/helpdata/en/1d/df5f57127111d3b9390000e8353423/content.htm
    I hope, it will help in you inresolving your problem.
    by
    Prasad GVK.

  • Help on Calling a method from another class

    how can i call a method from another class.
    Class A has 3 methods
    i just want to call only one of these 3 methods into my another class.
    How can I do that.

    When i am trying this
    A a=new A;
    Its calling all the methods from class A. I just want
    to call a specfic method.How can it be done?When i am trying this
    A a=new A();
    Its calling all the methods from class A. I just want to call a specfic method.How can it be done?

Maybe you are looking for

  • Sort photos in album in iCloud Photo

    I have created an Album and added photos to it, but the order appears random. Is there a way to reorder/sort the photos by date?  Like in the moments view. Thx,

  • J2ME Web Services proxy

    I try to register a web service with mobile studio, (I use my account on studio.oraclemobile.com) so as to generate J2ME stub and run the service in proxy mode. The problem is, whichever URL I put for wsdl files, I get "The URL you entered does not c

  • Check Portal System Database Backup status

    Hi, we have a portal system and i have performed an online DB-Backup using brtools. Like DB02 in ABAP Stack, is there a way to display the status of the Backup either using NWA at SAP level or using brtools at OS level ? Thank you, Mohan.

  • Bookmarks disappeared on android app

    I just discovered the bookmark-adding function, which is great. But then my bookmarks disappeared. I had about 10 of them, points I needed to review later in a large textbook, and now they are gone. It's happening in other books, too. I tried to repr

  • Nomad Zen Xtra - 60G - Major Issues

    I bought the Zen Xtra for my husband for his b-day last April (2004). Over the summer the Zen Xtra worked well and transfer of 307 tracks of songs was successful. Then, in the fall we decided to try setting up playlists through the Creative MediaSour