Problem calling method rec

folks here's a look at my code
public Date getBusinessDate(Date start , Date end )
     int days = 0;
          Calendar startcal = Calendar.getInstance();
          startcal.setTime(start);
          while(startcal.getTime().getTime() < end.getTime())
               startcal.add(Calendar.DATE,1);
               int day = startcal.get(Calendar.DAY_OF_WEEK);
               if( day == Calendar.MONDAY || day == Calendar.TUESDAY || day == Calendar.WEDNESDAY ||
                         day == Calendar.THURSDAY || day == Calendar.FRIDAY)
                    continue;
               days++;
          startcal.add(Calendar.DATE , (days));
          Date recursiveEnd = startcal.getTime();
          if(days > 0)
          getBusinessDate(end , recursiveEnd);
          System.out.println("The date is"+recursiveEnd);
          return (recursiveEnd);
what I am trying to do here is trying to pass on 2 dates to this method which in turn will return me result date which takes into account the weekends and does not count the weekends (it just counts the business days).
I am calling the function again at the end to make sure that the days added to startcal object does not have a weekend again.
my output with the final println is
The date isMon Jan 01 09:44:43 GMT-05:00 2007
The date isMon Jan 01 09:44:43 GMT-05:00 2007
The date isSun Dec 31 09:44:43 GMT-05:00 2006
The date isSat Dec 30 09:44:43 GMT-05:00 2006
i do not have the println in a loop and it still prints 4 times why?
jan 01 is the date it shld be returnin then why is it returnin dec 30?
thanks a lot for your patience

yeah i understand that but why is returnin me the date dec 30 instead of jan1 which I am expecting when I call this function from somewhere else. you mean to say the return in the end is invoked the number of times getBusinessDays is called?
i guess i have a hint of the above but waitin to hear from you guyz and what could be a probable solution to the above?

Similar Messages

  • Problem calling methods

    I am having trouble calculating the area and perimeter. I know the methods are right, but I just don't know how to call them to make them do the work. I've tried just about everything I can think of. Can anybody tell me what I am doing wrong? Thanks in advance!
    Sample output:
    Enter length of rectangle:
    2
    Enter width of rectangle:
    4
    Area: 0.0
    Perimeter: 4.0
    Press any key to continue . . .
    import java.util.Scanner;
    import java.text.DecimalFormat;
    public class Rectangle
         public double length;
         public double width;
         public Rectangle()
              length = 0;
              width = 0;
         public double getLength()
              return length;
         public double getWidth()
              return width;
         public void setLength(double length)
              this.length = length;
         public void setWidth(double width)
              this.width = width;
         public double area(Rectangle R)
              double area = length * width;
              return area;
         public double perimeter(Rectangle R)
              double perimeter = (length * 2) + (width * 2);
              return perimeter;
    /*     public String toString()
              double area = 0;
              double perimeter = 0;
              return "Area: " + area + "\tPerimeter: " + perimeter;
         public static void main(String [] args)
              DecimalFormat onePlace = new DecimalFormat("#0.0");
              Rectangle R = new Rectangle();
              Rectangle L = new Rectangle();
              Rectangle W = new Rectangle();
              Scanner input = new Scanner(System.in);
              System.out.println("Enter length of rectangle: ");
              L.setLength(input.nextDouble());
              System.out.println("\nEnter width of rectangle: ");
              W.setWidth(input.nextDouble());
              System.out.println("\nArea: " + onePlace.format(L.area(W)));
              System.out.println("Perimeter: " + onePlace.format(L.perimeter(R)));
    //          System.out.println(R.toString());
    }

    Judging from your sample output there is only one rectangle
    involved in the problem.
    Your main() method should reflect this fact. Remove the three
    new Rectangle() lines and replace them with by declaring a single
    rectangle. Set the rectangle's width and height, then obtain its
    perimeter and area.

  • Hey There, Wee Problem Calling Methods!

    Hey theree, i have designed auser interface that will eventually do a number of functions. The code below shows this
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    import java.io.File;
    * ImageViewer is the main class of the image viewer application. It builds and
    * displays the application GUI and initialises all other components.
    * To start the application, create an object of this class.
    * @author Michael Kolling and David J Barnes
    * @version 1.0
    public class Interface
        // constants:
        private static final String VERSION = "Version 1.0";
        private static JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir"));
        // fields:
        private JFrame frame;
        private ImagePanel imagePanel;
        private JLabel filenameLabel;
        private JLabel statusLabel;
        private ImageInfo currentImage;
        PresentedTable pt = new PresentedTable();
        Container contentPane;
         * Create an area for artwork and show it on screen.
        public Interface()
            currentImage = null;
            makeFrame();
        // ---- implementation of menu functions ----
         * Open function: open a file chooser to select a new image file.
        private void openFile()
            int returnVal = fileChooser.showOpenDialog(frame);
            if(returnVal != JFileChooser.APPROVE_OPTION) {
                return;  // cancelled
            File selectedFile = fileChooser.getSelectedFile();
            currentImage = ImageFileManager.loadImage(selectedFile);
            if(currentImage == null) {   // image file was not a valid image
                JOptionPane.showMessageDialog(frame,
                        "The file was not in a recognized image file format.",
                        "Image Load Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            imagePanel.setImage(currentImage);
            showFilename(selectedFile.getPath());
            showStatus("File loaded.");
            frame.pack();
         * Close function: close the current image.
        private void close()
            currentImage = null;
            imagePanel.clearImage();
            showFilename(null);
         * Quit function: quit the application.
        private void quit()
            System.exit(0);
         private void showAbout()
            JOptionPane.showMessageDialog(frame,
                        "ImageViewer\n" + VERSION,
                        "About ImageViewer",
                        JOptionPane.INFORMATION_MESSAGE);
    //View Current Table
    private void view()
    PresentedTable.createAndShowGUI();//createAndShowGUI();
    contentPane.add(PresentedTable.createAndShowGUI(), BorderLayout.CENTER);
    frame.setVisible(true);
        //supporting methods
         * Display a file name on the appropriate label.
        private void showFilename(String filename)
            if(filename == null) {
                filenameLabel.setText("There Is Nothing Displayed.");
            else {
                filenameLabel.setText("File: " + filename);
         * Display a status message in the frame's status bar.
        private void showStatus(String text)
            statusLabel.setText(text);
        // ---- swing stuff to build the frame and all its components ----
         * Create the Swing frame and its content.
        private void makeFrame()
            frame = new JFrame("Interface");
            makeMenuBar();
            contentPane = frame.getContentPane();
            // Specify the layout manager with nice spacing
            contentPane.setLayout(new BorderLayout(6, 6));
            filenameLabel = new JLabel();
            contentPane.add(filenameLabel, BorderLayout.NORTH);
            imagePanel = new ImagePanel();
            contentPane.add(imagePanel, BorderLayout.CENTER);
            statusLabel = new JLabel(VERSION);
            contentPane.add(statusLabel, BorderLayout.SOUTH);
            // building is done - arrange the components and show       
            showFilename(null);
            frame.pack();
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2);
            frame.setVisible(true);
            frame.setSize(600,600);
         * Create the main frame's and its menu bar.
        private void makeMenuBar()
            final int SHORTCUT_MASK =
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
            JMenuBar menubar = new JMenuBar();
            frame.setJMenuBar(menubar);
            JMenu menu;
            JMenuItem item;
            // create the File menu
            menu = new JMenu("File");
            menubar.add(menu);
            //Allows the user to open a range Of Artwork by featured artists within the table
            item = new JMenuItem("Open Artwork");
                item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_MASK));
                item.addActionListener(new ActionListener() {
                                   public void actionPerformed(ActionEvent e) { openFile(); }
            menu.add(item);
            //Allows the user to save the current status of the table
            item = new JMenuItem("Save As");
            item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, SHORTCUT_MASK));
            menu.add(item);
            //Allows the user to close the cuurent image displayed and eitherload
            //a new image or perform anew task
            item = new JMenuItem("Close Current Image");
                item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, SHORTCUT_MASK));
                item.addActionListener(new ActionListener() {
                                   public void actionPerformed(ActionEvent e) { close(); }
            menu.add(item);
            menu.addSeparator();
            //Allows the user to exit appliction
            item = new JMenuItem("Quit Application");
                item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK));
                item.addActionListener(new ActionListener() {
                                   public void actionPerformed(ActionEvent e) { quit(); }
            menu.add(item);
            // create the Edit menu
            menu = new JMenu("Edit");
            menubar.add(menu);
            //Add a brand new record to the table
            item = new JMenuItem("Add A Brand New Record");
            item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, SHORTCUT_MASK));
                //item.addActionListener(new ActionListener());
                menu.add(item);
            //allows the user to amend an existing record     
            item = new JMenuItem("Amend An Existing Record");
            item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, SHORTCUT_MASK));
                //item.addActionListener(new ActionListener());
                menu.add(item);
            //Allows the user to display the current table
            item = new JMenuItem("View The Collection");
            item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, SHORTCUT_MASK));
            //item.addActionListener(new ActionListener(){
                    //public void actionPerformed(ActionEvent e){ view(); }
                frame.setVisible(true);
                menu.add(item);
            // put a spacer into the menubar, so the next menu appears to the right
            menubar.add(Box.createHorizontalGlue());
            // create the Help menu
            menu = new JMenu("Help");
            menubar.add(menu);
            item = new JMenuItem("This is a test");
                item.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) { showAbout(); }
            menu.add(item);
    I have also wriiten a class that will produce a table when the user creates an instance of it in main. Below:import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.lang.Object;
    public class PresentedTable extends JPanel {
    private boolean DEBUG = false;
    public PresentedTable() {
    super(new GridLayout(1,0));
    String[] columnNames = {"Name",
    "Album Title",
    "Running Time(in Minutes)",
    "# of Tracks"};
    String[][] data = {{"Jeff Buckley", "Grace",
    "Sixty minutes", "11"},
    {"Pete Yorn", "Day I Forgot",
    "Forty Five Minutes", "11"},
    {"Jack Johnson", "In Between Dreams",
    "Fifty Eight Minutes", "16"},
    {"Nine Days", "The Madding Crowd",
    "Forty Three Minutes", "14"},
    {"Nada Surf", "Let Go",
    "Sixty Two Minutes", "16"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"},
    {"Enter Artist Name", "Enter Album Title","Enter Running Time", "Enter Number Of tracks"}
    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(800, 100));
    if (DEBUG) {
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    printDebugData(table);
    //Create the scroll pane
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane.
    add(scrollPane);
    private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
    public static PresentedTable createAndShowGUI() {
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create window.
    JFrame frame = new JFrame("PresentedTable");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create content pane.
    PresentedTable newContentPane = new PresentedTable();
    newContentPane.setOpaque(true);
    frame.setContentPane(newContentPane);
    //Displaywindow.
    frame.setVisible(true);
    frame.pack();
    return newContentPane;
    public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    PresentedTable pt = new PresentedTable();
    IS there any way i can display the table (not necessarily) in the image panel because this is impossible. All i want to do is display the tabel when view the collection is clicked in the interface.
    I have begun to try this but i have failed misserably, any ideas? if you look in the first batch iof code you will c i have tried this method
    //View Current Table
    private void view()
    What am i doing wrong?

    Please reformat your post so that it is readable. When you post code, please post it between [code] and [/code] tags (you can use the "code" button on the message posting screen). It makes your code much easier to read and prevents accidental markup from the forum software.
    Formatting tips

  • Problem while sending ByteArray from as3 client through netconnection call method to red5 server

    Hi to all,
    I'm trying to send from as3 client a ByteArray of more or less 3 MB using NetConnection's call method but I am unable to do it, cause I get a timeout on the server and the client get disconnected (I have also increased the timeout limit in red5.properties but nothing changed). If I try to send a smaller ByteArray I don't have problem, even if the trasfer is really slow.
    Any solution?
    thanks

    put it in code tags so it's readable
    CLIENT
    public void sendLoginData(String data)
    int c=0;
    byte loginData[]=new byte[data.length()];
    loginData=data.getBytes();
    try
    out.write(loginData);
    System.out.println(client.isClosed());
    // here i want 2 receive the 1 byte data whch i hv sent frm server's RUN() method
    //following code is not working :( it gets hanged
    while((c=in.read())!=-1)
    System.out.print(c);
    System.out.print("hi");
    catch(Exception e)
    System.out.println("Caught:" + e);
    finally
    out.close();
    }SERVER
    public void run()
    boolean flag;
    try
    flag=verifyLoginData(ID); //this function verifies the login data by connecting to DB
    System.out.println(flag);
    if(flag==true)
    //send login valid
    bos.write(1);
    bos.close();
    else
    //send login invalid
    bos.write(0);
    bos.close();
    catch(Exception e)
    System.out.println("caught " + e);
    }

  • JSObject call() method problem

    Hi,
    I created an applet and I call a javascript function from the applet using call() method of jsobject.
    JSObject jsoWindow=Jmol.jsoWindow;
              String[] args = {"Fred"};
              jsoWindow.call("f", args);
    and i wrote an alert in the js function "f". It is working nicely in IE6, IE7 and Mozilla 2.x.x.x. But when I run it in Mozilla 1.5, it is nor working. I didn't get any alert.
    What is the problem? Anybody can tell me a soltn for this?
    Is any other method to call a js function from applet?
    Im waiting for ur reply.
    thanks
    ani

    Thanks for your reply.
    Then what can I do? Is I want to do any settings?
    Pls reply

  • Problem calling AS3 class's methods from Flex Project

    Sorry if this is a stupid question, but after 2 days of Web
    searching and 2 books give up; I am a Java and c# programmer and am
    having problems calling AS3 classes (in packages) from Flex Builder
    2 Flex Projects; the AS3 classes work great as Flex Builder "AS3
    Projects", but when I try to use the classes in a Flex Builder
    "Flex Project" I am able to see and set their properties, but
    cannot see (through "code completion") their methods (unless the
    class extends another AS3 class; and in that case I can see the
    base class's methods). Here is the code:
    AS3 Example Class:
    package asText {
    public class CheckWord {
    public var strData:String;
    public var strAProperty:String;
    public var intAProperty:int;
    // Constructor
    public function CheckWord() {
    public function TestMethod():void {
    trace("test...");
    public function WordLength():int {
    var intLength:int = 0;
    trace(strData);
    intLength = strData.length;
    return intLength;
    } // From Method WordLength
    } // From Class CheckWord
    } // From Package asText
    The MXML code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute"
    width="442" height="488" horizontalAlign="center"
    verticalAlign="middle"
    backgroundGradientColors="[#c0c0c0, #c0c0c0]"
    xmlns:asTheText="asText.*"
    >
    <asTheText:CheckWord strData="Test words" />
    <mx:Panel title="Welcome to ........" width="337"
    height="393" horizontalAlign="center" verticalAlign="middle"
    layout="absolute" y="15" x="50">
    <mx:Text text="First Name" enabled="true" width="68"
    fontWeight="bold" x="27.25" y="36"/>
    <mx:TextInput id="txtFName" x="112.25" y="34"/>
    <mx:Text text="Last Name" enabled="true" width="68"
    fontWeight="bold" x="27.25" y="66"/>
    <mx:TextInput x="112.25" y="64" id="txtLName"/>
    <mx:Text text="email address" enabled="true" width="87"
    fontWeight="bold" x="17.25" y="96"/>
    <mx:TextInput width="189" id="txtEmail" left="112.25"
    top="94"/>
    <mx:Button id="butSubmit" label="Submit" x="95" y="194"
    click="asTheText:TestMethod();"/>
    ..............and so on ............
    All this does is give me an 1180 error:
    1180: Call to a possibly undefined method TestMethod.
    flexConveyMovie1.mxml

    Thanks, I have it working; I was not assigning an "ID" to the
    "MXML use of the class" (whatever the formal name for that is;
    like: <asTheText:CheckWord id="MyText" strData="The Data" />
    ) and then I was not referencing that ID in what I am refering to
    as calling methods for the Class; like:
    <mx:Button id="butTest" label="Test Function" x="39"
    y="208" click="MyText.TestMethod();"/>
    Also, I did some tests on this, and I am shocked that
    apparently neither of these two "uses"(?) of a custom AS3 class
    actually "call" the Class's constructor. Does that make sense or is
    that the result of how I am structuring this?
    Phil

  • Native - Java Method Call problem - "Wrong Method ID..."

    I am writing a 3d game engine using c++, with all the game logic code in Java, for the purpose of making the thing extendible, easily modifyable, etc...
    I am using J2SE JDK 1.2.2.
    Most things work fine (engine-wise), but i have a few questions about problems i am having getting the JNI to work correctly with calls to Java Methods.
    1. If I use FindClass() to get a jclass reference to a named class, I get one number back. If I then instantiate this class, and then call GetObjectClass() with the instance, I get another number, **which doesnt appear to work for anything**. What is going on here? Can the JVM give different jclass numbers for the same class? Is GetObjectClass() supposed to work?
    2. Is AllocObject() alright for instantiating Java objects? It does seem to allocate memory, and method calls work to the new object. I am aware that it doesn't call a constructor, but I like that, seeing as the initialization is handled through a different [network-synchronized] means.
    3. Using a jclass retrieved using FindClass(), which I store in a global variable, I am able to call methods on an instance that I created in a certain function. I then make sure (?) that the GC can't reclaim the class or object memory by getting a NewGlobalReference to both of them [just to be safe]. However, in a later function, I am unable to call methods using my stored method IDs, ["Wrong Method ID....JVM has been asked to shut down this application in an unusual manner..."]. I am also unable to acquire new methodIDs, as the system returns 0xCCCCCCCC for all method ID queries. Obviously, attempting to use those bogus method IDs results in a JVM crash, in a segment called [2 deep in the untraceable depths of JVM.dll] from the JNI CallVoidMethodV() function. Why is this happening? Is the GC getting in there despite my best efforts? Is it illegal to cache methodIDs, jclass references or jobject references? aaarrggh! :)
    Thanks
    Chris Forbes
    Lead Programmer
    Sprocket Interactive
    [email protected]

    Hi Chris,
    I hit the same sort of problem, when writing a JVMDI ( VM debugger hook ), in C++.
    My question remained unanswered too
    http://forum.java.sun.com/thread.jsp?forum=47&thread=461503&tstart=30&trange=30
    I didn't try a call to NewGlobalRef, as you did... but it sounds like it could be what I was missing.
    I've a couple of ideas, but nothing definite for you.
    1) maybe there's more than one classloader, so that multiple copies of the class are loaded
    2) ensure you're compiling your DLL with "quad-word" ( 8 byte ) alignment.
    Otherwise all your JNI references will be misaligned !
    Since the JNI reference maps to a C++ pointer, it's possible that you can't cache any JNI references.
    That's my vague feeling on the subject.
    As a workaround, you may have to keep requesting any JNI references, eg. jclass & jmethod's, as you need them.
    regards,
    Owen

  • CALL METHOD ABAP run SQL wrong

    Dear All
             I have a problem in ABAP connect SQL,Below is my code snippet sentence.
    CONCATENATE 'Insert Into [timportcortrol]'
                    '(zucode,zstate,zdate,zkind) Values('''
                      VG_PCID ''','''
                      '1'','''
                      SY-DATUM ''','''
                      '1' ''')'
                     INTO SQL.
        CALL METHOD OF REC 'Execute'
         EXPORTING #1 = SQL
         #2 = CON
         #3 = '1'.
    IF NOT SY-SUBRC = 0.
        MESSAGE I000 WITH 'Download  to [timportcortrol] failure,Please Check the SQL Connect!!! '.
        EXIT.
      ENDIF.
    Con:is the connect SQL String ,the connect SQL is Okay.
    I debug this code,when I used u2018Select u2026sentenceu2019,the program can work.if I  use u2018insert intou2019 then canu2019t work,but I copied the SQL of the u2018inset Into sentenceu2026u2019run it into SQL server then it can work also.
    And I found the SY-SUBRC eq u20182u2019.whatu2019s mean about of the sy-subrc eq u20182u2019.
    I think the insert into sentence in abap I have write the wrong ,but I canu2019t assurance.
    The Insert Into Sentence is:u2019 Insert Into [timportcortrol](zucode,zstate,zdate,zkind) Values('20080807094713','1','20080807','1')u2019
    Could you give me some advice for this issue?
    Thanks of all
    Sun.

    Have you checked whether it's a problem with mixed case?  Some SQL dialects are case sensitive.
    The not very helpful meanings of the sy-subrc value can be found in ABAP help.
    0 Successful processing of the method meth.
    1 Communication Error to SAP GUI.
    2 Error when calling method meth.
    3 Error when setting a property.
    4 Error when reading a property
    matt

  • Problem calling two perl modules from java in seperate threads(JVM CRASHES)

    Dear Friends,
    I have one severe problem regarding calling perl modules from java
    I had to call two perl modules simultaneously (i.e.) from two threads,,, but jvm crashes when one of the perl calls is exiting earlier
    I am unable to spot out why ....
    For calling perl from java ...., We are first calling C code from java using JNI and then Perl code from C
    All works fine if we call only one perl call at a time.... If we call them in a synchronized manner the JVM is not crashing .... But we don't want blocking..
    The following is the code snippet
    <JAVA FILE>
    class Sample
         static {
              System.loadLibrary("xyz");  // Here xyz is the library file generated by compiling c code
         public native void call_PrintList();
         public native void call_PrintListNew();
         Sample()
              new Thread1(this).start();     
         public static void main(String args[])
              System.out.println("In the main Method");
              new Sample().call_PrintList();
         class Thread1 extends Thread
              Sample sample;
              Thread1(Sample sam)
                   sample=sam;
              public void run()
                   sample.call_PrintListNew();     
    }<C FILE>
    #include <EXTERN.h>
    #include <perl.h>
    static PerlInterpreter *my_perl;
    static char * words[] = {"alpha", "beta", "gamma", "delta", NULL } ;
    static void
    call_PrintList(){
         printf("\nIn the Call method of string.c\n");
            char *wor[] = {"hello", "sudha", NULL } ;
               char *my_argv[] = { "", "string.pl" };
               PERL_SYS_INIT3(&argc,&argv,&env);
               my_perl = perl_alloc();
                   PL_perl_destruct_level = 1; //// We have mentioned this also and tried removing destruct call
               perl_construct( my_perl );
               perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
              PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
               perl_run(my_perl);
         dSP ;
            perl_call_argv("PrintList",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
    //     perl_destruct(my_perl);
    //          perl_free(my_perl);
    //           PERL_SYS_TERM();
    static void
    call_PrintListNew(){
    printf("In the new call method\n");
    char *wor[] = {"Hiiiiiiiiiiiiiii", "Satyam123333", NULL } ;
            char *my_argv[] = { "", "string.pl" };
            PERL_SYS_INIT3(&argc,&argv,&env);
            my_perl = perl_alloc();
    PL_perl_destruct_level = 1;
            perl_construct( my_perl );
            perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
            perl_run(my_perl);
            dSP ;
            perl_call_argv("PrintListNew",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
      //      perl_destruct(my_perl);
      //      perl_free(my_perl);
       //     PERL_SYS_TERM();
    void callNew()
    call_PrintListNew();
    void call ( )
    call_PrintList();
    //char *wor[] = {"hello","sudha",NULL};
    /*   char *my_argv[] = { "", "string.pl" };
          PERL_SYS_INIT3(&argc,&argv,&env);
          my_perl = perl_alloc();
          perl_construct( my_perl );
          perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
         PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
          perl_run(my_perl);*/
       //   call_PrintList();                      /*** Compute 3 ** 4 ***/
    /*      perl_destruct(my_perl);
          perl_free(my_perl);
          PERL_SYS_TERM();*/
        }And Finally the perl code
    sub PrintList
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
    sub PrintListNew
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
            }Please help me in this regard

    Dear Friends,
    I have one severe problem regarding calling perl modules from java
    I had to call two perl modules simultaneously (i.e.) from two threads,,, but jvm crashes when one of the perl calls is exiting earlier
    I am unable to spot out why ....
    For calling perl from java ...., We are first calling C code from java using JNI and then Perl code from C
    All works fine if we call only one perl call at a time.... If we call them in a synchronized manner the JVM is not crashing .... But we don't want blocking..
    The following is the code snippet
    <JAVA FILE>
    class Sample
         static {
              System.loadLibrary("xyz");  // Here xyz is the library file generated by compiling c code
         public native void call_PrintList();
         public native void call_PrintListNew();
         Sample()
              new Thread1(this).start();     
         public static void main(String args[])
              System.out.println("In the main Method");
              new Sample().call_PrintList();
         class Thread1 extends Thread
              Sample sample;
              Thread1(Sample sam)
                   sample=sam;
              public void run()
                   sample.call_PrintListNew();     
    }<C FILE>
    #include <EXTERN.h>
    #include <perl.h>
    static PerlInterpreter *my_perl;
    static char * words[] = {"alpha", "beta", "gamma", "delta", NULL } ;
    static void
    call_PrintList(){
         printf("\nIn the Call method of string.c\n");
            char *wor[] = {"hello", "sudha", NULL } ;
               char *my_argv[] = { "", "string.pl" };
               PERL_SYS_INIT3(&argc,&argv,&env);
               my_perl = perl_alloc();
                   PL_perl_destruct_level = 1; //// We have mentioned this also and tried removing destruct call
               perl_construct( my_perl );
               perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
              PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
               perl_run(my_perl);
         dSP ;
            perl_call_argv("PrintList",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
    //     perl_destruct(my_perl);
    //          perl_free(my_perl);
    //           PERL_SYS_TERM();
    static void
    call_PrintListNew(){
    printf("In the new call method\n");
    char *wor[] = {"Hiiiiiiiiiiiiiii", "Satyam123333", NULL } ;
            char *my_argv[] = { "", "string.pl" };
            PERL_SYS_INIT3(&argc,&argv,&env);
            my_perl = perl_alloc();
    PL_perl_destruct_level = 1;
            perl_construct( my_perl );
            perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
            perl_run(my_perl);
            dSP ;
            perl_call_argv("PrintListNew",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
      //      perl_destruct(my_perl);
      //      perl_free(my_perl);
       //     PERL_SYS_TERM();
    void callNew()
    call_PrintListNew();
    void call ( )
    call_PrintList();
    //char *wor[] = {"hello","sudha",NULL};
    /*   char *my_argv[] = { "", "string.pl" };
          PERL_SYS_INIT3(&argc,&argv,&env);
          my_perl = perl_alloc();
          perl_construct( my_perl );
          perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
         PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
          perl_run(my_perl);*/
       //   call_PrintList();                      /*** Compute 3 ** 4 ***/
    /*      perl_destruct(my_perl);
          perl_free(my_perl);
          PERL_SYS_TERM();*/
        }And Finally the perl code
    sub PrintList
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
    sub PrintListNew
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
            }Please help me in this regard

  • Problem calling a EJB Java Client from Java Activity Agent

    Hi,
    We have a wrapper java class that calls to an EJB through a JNDI lookup. The wrapper class is called from a workflow. The problem is that the call fail with the following message error:
    Error : getRemoteHome Lugar: ServiceLocator NamingException Mensaje Error: Receive timed out
    Mon Jan 09 15:32:13 EST 2006 Enqueuing VIC/97513 com.tallion.tax.workflow.assessment.Update
    F_FN_ERROR (MODULE=com.tallion.tax.workflow.assessment.Update) (ITEMTYPE=VIC) (ITEMKEY=97513) (ACTID=10617) (FUNCMODE=RUN) (ERRMESSAGE=getRemoteHome Lugar: ServiceLocator NamingException Mensaje Erro
    The wrapper class has in their classpath a jndi.properties as follows:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.provider.url=69.0.137.120:1099
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    The call just works fine when we restart the Java Activity Agent and then, after a while it fails again with the same error.
    Any ideas/workaround?
    Thanks.

    I have a situation that is a bit similar. I have successfully used beans for storing methods used in JSPs and used by other methods in the same class as was suggested above. Now I would like to break some methods into another (utility) class since they are lower level and can be used by lots of things. They are for database operations (given a String query and String dbname, it queries and returns ResultSet for example). I want to have them in a separate class for reusability and OOP.
    I am having problems calling those public static methods in the public class from my bean that communicates with the JSP. I can't compile the class that calls the method in the database ops class. I get an error like :
    loginHelper.java:45: cannot find symbol
    symbol : variable sqlHelper
    location: class dbHelperBean.loginHelper
    and when I include the package name in the call I get
    loginHelper.java:45: cannot find symbol
    symbol : class sqlHelper
    location: package dbHelperBean
    That's strange since the package of both classes is dbHelperBean and the class is indeed called sqlHelper. I tried to compile it in the same directory as sqlHelper as well. What am I doing wrong?
    Thanks for any help.

  • *ERROR IN OLE CALL - METHOD CALL ERROR...*

    HI ..
    When trying to Upload a file using BDC with Vista OS, we are getting the following error..
    ERROR IN OLE CALL - METHOD CALL ERROR...
    There is no problem with BDC as its working fine with XP & other OS.
    Pls help!!

    Seems that you are working with microsoft files.
    Maybe you are using deprecated functions like WS_EXCEL

  • How to call methods from within run()

    Seems like this must be a common question, but I cannot for the life of me, find the appropriate topic. So apologies ahead of time if this is a repeat.
    I have code like the following:
    public class MainClass implements Runnable {
    public static void main(String args[]) {
    Thread t = new Thread(new MainClass());
    t.start();
    public void run() {
    if (condition)
    doSomethingIntensive();
    else
    doSomethingElseIntensive();
    System.out.println("I want this to print ONLY AFTER the method call finishes, but I'm printed before either 'Intensive' method call completes.");
    private void doSomethingIntensive() {
    System.out.println("I'm never printed because run() ends before execution gets here.");
    return;
    private void doSomethingElseIntensive() {
    System.out.println("I'm never printed because run() ends before execution gets here.");
    return;
    }Question: how do you call methods from within run() and still have it be sequential execution? It seems that a method call within run() creates a new thread just for the method. BUT, this isn't true, because the Thread.currentThread().getName() names are the same instead run() and the "intensive" methods. So, it's not like I can pause one until the method completes because they're the same thread! (I've tried this.)
    So, moral of the story, is there no breaking down a thread's execution into methods? Does all your thread code have to be within the run() method, even if it's 1000 lines? Seems like this wouldn't be the case, but can't get it to work otherwise.
    Thanks all!!!

    I (think I) understand the basics.. what I'm confused
    about is whether the methods are synced on the class
    type or a class instance?The short answer is; the instance for non-static methods, and the class for static methods, although it would be more accurate to say against the instance of the Class for static methods.
    The locking associated with the "sychronized" keyword is all based around an entity called a "monitor". Whenever a thread wants to enter a synchronized method or block, if it doesn't already "own" the monitor, it will try to take it. If the monitor is owned by another thread, then the current thread will block until the other thread releases the monitor. Once the synchronized block is complete, the monitor is released by the thread that owns it.
    So your question boils down to; where does this monitor come from? Every instance of every Object has a monitor associated with it, and any synchronized method or synchonized block is going to take the monitor associated with the instance. The following:
      synchronized void myMethod() {...is equivalent to:
      void myMethod() {
        synchronized(this) {
      ...Keep in mind, though, that every Class has an instance too. You can call "this.getClass()" to get that instance, or you can get the instance for a specific class, say String, with "String.class". Whenever you declare a static method as synchronized, or put a synchronized block inside a static method, the monitor taken will be the one associated with the instance of the class in which the method was declared. In other words this:
      public class Foo {
        synchronized static void myMethod() {...is equivalent to:
      public class Foo{
        static void myMethod() {
          synchronized(Foo.class) {...The problem here is that the instance of the Foo class is being locked. If we declare a subclass of Foo, and then declare a synchronized static method in the subclass, it will lock on the subclass and not on Foo. This is OK, but you have to be aware of it. If you try to declare a static resource of some sort inside Foo, it's best to make it private instead of protected, because subclasses can't really lock on the parent class (well, at least, not without doing something ugly like "synchronized(Foo.class)", which isn't terribly maintainable).
    Doing something like "synchronized(this.getClass())" is a really bad idea. Each subclass is going to take a different monitor, so you can have as many threads in your synchronized block as you have subclasses, and I can't think of a time I'd want that.
    There's also another, equivalent aproach you can take, if this makes more sense to you:
      static final Object lock = new Object();
      void myMethod() {
        synchronized(lock) {
          // Stuff in here is synchronized against the lock's monitor
      }This will take the monitor of the instance referenced by "lock". Since lock is a static variable, only one thread at a time will be able to get into myMethod(), even if the threads are calling into different instances.

  • NullPointer when GUI calls method in Client

    Hi, I'm relatively new to Java programming and this conference.
    I hope the following is not too long winded.
    I'm trying to programme a FTP Client which is controlled by a GUI.
    My JBuilder project has three classes:
    ClientGUI.java and ClientFrame.java (produced with JBUilder's New Application option)
    plus AClient.java (this is the 'engine' of the project).
    ClientGUI constructs an instance 'frame' of ClientFrame which in turn constructs an instance 'client' of AClient.
    The call to the AClient constructor has to be in a try/catch statement,
    and takes a JTextArea as a parameter from ClientFrame to allow 'client' to display messges in my GUI.
    The AClient constructor opens the Socket connection to a simple server on the same computer.
    This part works.
    However, when I attempt to use events generated by buttons in my GUI ('frame')to call methods in 'client', I get the following null-pointer exception:-
    java.lang.NullPointerException
    at ClientFrame.jButton1_actionPerformed(ClientFrame.java:219)
    at ClientFrame_jButton1_actionAdapter.actionPerformed(ClientFrame.java:274)
    etc...
    etc...
    These refer to code blocks:-
        if ( client.isAlive() ) {  /*line 219*/
          System.out.println("client alive");
        }where isAlive() is a simple test method that returns true,
    and
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);  /*line 274*/
      }'client' is listed as a public field in ClientFrame and is instanciated, so why do I have this problem?
    Enclosing the call in a try/catch statement doesn't help.
    Thanks in advance. Laurence

    The NullPointer means that the client was not instantiated, though you may think it has been.
    Make sure that you are instantiating the correct variable, for instance, if you have a class-level field called client you would do something like this:
    public class WhateverClass {
      private AClient client;
      //other stuff
      public WhateverClass(...) {
        client = //assignment either
                 //with new AClient(...)
                 //or something else
      }You would NOT do:
    public class WhateverClass {
      private AClient client;
      //other stuff
      public WhateverClass(...) {
        AClient client = //assignment either
                         //with new AClient(...)
                         //or something else
      }Since this would create a second variable of name client that only has scope within the constructor.
    Also, if the client is being assigned through a parameter in the constructor, check to make sure that that you are not passing a null value along... Do a System.out.println(client) after the assignement and see what you get. Then you know if the problem occurs in this class or in the class that creates the AClient reference to begin with...

  • Call method cl_crm_documents- create_with_file not creating attachment

    Hi,
    I am trying to create attachment in a transaction type using cl_crm_documents->create_with_file. But it is not creating the same, instead gives error "Error loading file &".
    I am uploading a file with fields object_id, text, file name, description  and category.
    I have passed the parameters as follows:
    data: gref_obj           type ref to cl_crm_documents.
    create object gref_obj.
              gw_prop_attr-name           = 'BDS_KEYWORD'.
              gw_prop_attr-value          = gw_attach-category.
              append gw_prop_attr to gt_prop_attr.
              gs_business_object-instid   = gw_guid-guid.(object guid)
              gs_business_object-typeid   = gv_object_type.(object type)
              gs_business_object-catid    = 'BO'.
              call method gref_obj->create_with_file
                exporting
                  file_name       = gw_attach-f_name (name as provided in my uploaded file, in my case it is test)
                  directory       = p_floder (C:\Attachment\)
                  properties      = gt_prop_attr
                  business_object = gs_business_object
                importing
                  phio            = gs_phio_id
                  loio            = gs_loio_id
                  error           = ls_error.
    Please help me on this. I doubt the directory that I am giving is wrong.
    Thanks.

    Hi,
    Please go through this...
    Re: Problem attach document with the FileUpload UI.
    Cheers,
    Kris.

  • How to call methods at selection screen?

    Hi all,
    I am developing a program in object oriented abap.
    i have defined a class and implementated, and we have to instantiate the class in start of selection.
    now the problem is how to call a method at selection screen event.
    i want to validate the inputs entered by users. so can i create a static method which can be called without instantiating a class?
    please guide me
    thanks

    Hello Mr A,
    Define the method as a Static Method and that will solve your problem. Static methods can be called directly and does not need the class to be instantiated before it can be called.
    Data: my_class type ref to zcl_report_utilities.
    At Selection-Screen.
    Call Method zcl_report_utilities=>check_selections
           exporting
              iv_repnm    = sy-cprog
            importing
              et_messages = lt_msgs.
    Start-Of-Selection.
      Create Object my_class
             exporting
                im_pernr  = ls_e1plogi-objid
                im_begda = c_lowdate
                im_endda = c_hidate.
       Call Method my_class->read_infotypes
              exporting
                 im_infty = c_org_assn
              changing
                 et_infty  = it_infty.
    Here you can see how the method check_selections is called before the class zcl_report_utilities is instantiated. The best part about the Static Methods is if you are writing the class in the Class Library (SE24), any other programs can call them directly (if they need to) without needing to instantiating the entire class before the call.
    Also note the difference in syntax when calling the static method check_selections to when calling the Instance method read_infotypes.
    Hope this solves your issue and please do not forget to reward points.
    Cheers,
    Sougata.
    p.s. if you are defining your class locally (program specific) then use Class-Methods to define a static method.
    Edited by: Sougata Chatterjee on May 1, 2008 9:53 AM

Maybe you are looking for

  • How can I make an image file from/to a V240 SPARC workstation?

    Scenerio: I have 4 V240 SPARC Workstations on a network. 1 of these servers is set up the way I want it with all necessary applications and drivers. I had assistance from a number of good people to do this and now I want to preserve this scsi image a

  • Dimension key 16 missing in dimension table /BIC/DZPP_CP1P

    Hi all, I have a problem with an infocube ZPP_CP1. I am not able to delete nor load any data. It was working fine till some time back. Below is the outcome of running RSRV check on this cube. I tried to run the error correction in RSRV. But n o use P

  • Big headaches! Can't get stuff to work!! Help!!!

    I have chased so many bunny trails trying to fix so many things that now I am just dazed and confused.  Let me start at the beginning because now I don't even know what's important and what isn't! 1) moved from dial-up to wireless internet service wi

  • Can iPhone Mail redirect mail to subfolders like the Apple desktop Mail app

    In my Mail app on my computer, I have Rules set up so that certain emails from various people get moved to a few different subfolders I have set up. However, in my iPhone, they all come to my primary email address. Is there any way to make iPhone mai

  • Zen Touch with Vi

    First of all, my knowledge of PC's etc is very limited, so when answering, can you make it as easy to understand as possible ?I?have a Zen Touch and have just bought a new lap top that runs Vista and has Windows Media player installed I have never up