Blocking method 'readline()' in class BufferedReader??

I have this in some code:
              BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        socket.getInputStream()));
              String inputLine, outputLine;
              while ((inputLine = in.readLine()) != null)
                        System.out.println("TEST");
                   outputLine = inputLine + " TXT ADDED";
                   out.println(outputLine);
              }The while loop only get executed each time my client sends a message. Where in the API does it say that readline() blocks the thread until a new message is recevied?
I thought that either the while loop terminates or else it runs all the time printing "TEST". I am not used to this kind of 'continuing conditinal' execution of a while loop so I guess there is something I missing?

Hey you're right. The BufferedReader API doesn't specifically mention blocking. However the Reader class (the superclass) mentions it. Actually I believe that all the input methods in java.io are blocking.
I'm not sure why you're not used to it. Blocking I/O is pretty common. In any event that's how it works. I believe that there is non-blocking I/O functionality provided in the java.nio package.

Similar Messages

  • Trouble writing a blocking method when asking GUI for input

    Hi,
    I think this is more of a thread question than a GUI question, so that is why i posted it here...
    My problem is I have a client/server application, and the client also has a GUI, which I get an input string from.
    My problem is, that I don't know how to write a blocking method, which will wait for the GUI's input.
    The example I provided below is very simple, and the obvious solution would be to use a JOptionPane, but that is not a viable solution. The way I am getting around this now is using a Thread.sleep call in my GUI, but I feel that this is incorrect, and there should be another way around it.
    Here is my server class (w/ main method)
    import java.net.*;
    import java.io.*;
    public class Server {
        public static void main(String[] args) throws IOException {
            ServerSocket serverSocket = null;
            try {
                serverSocket = new ServerSocket(4444);
            } catch (IOException e) {
                System.err.println("Could not listen on port: 4444.");
                System.exit(1);
            Socket clientSocket = null;
            try {
                clientSocket = serverSocket.accept();
            } catch (IOException e) {
                System.err.println("Accept failed.");
                System.exit(1);
            PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            String  outputLine;
            outputLine = "Temp String";
            out.println(outputLine);
             System.err.println("Client: " + in.readLine());
            outputLine = "Bye";
            out.println(outputLine);
            out.close();
            in.close();
            clientSocket.close();
            serverSocket.close();
    }Here is my client class (w/ main method)
    import java.io.*;
    import java.net.*;
    public class Client {
        public static void main(String[] args) throws IOException {
            Socket kkSocket = null;
            PrintWriter out = null;
            BufferedReader in = null;
            try {
                kkSocket = new Socket("localhost", 4444);
                out = new PrintWriter(kkSocket.getOutputStream(), true);
                in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: localhost.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: localhost.");
                System.exit(1);
            ClientGUI cg = new ClientGUI();
            String fromServer;
            String fromUser;
            while ((fromServer = in.readLine()) != null) {
                System.out.println("Server: " + fromServer);
                if (fromServer.equals("Bye."))
                    break;
                fromUser = cg.getInput();
             if (fromUser != null) {
                    System.out.println("Client: " + fromUser);
                    out.println(fromUser);
            out.close();
            in.close();
            kkSocket.close();
             System.exit(0);
    }and here is the ClientGUI class (note: you need to resize it in order to see the textbox....
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class ClientGUI extends JFrame {
         private JTextField textBox = new JTextField();
         private JButton input = new JButton("Submit");
         private boolean recievedInput = false;
         private String inputText = "";
         public ClientGUI() {
              this.setupGUI();
         private ActionListener buttonAction = new ActionListener() {
              public void actionPerformed(ActionEvent e)  {
                   inputText = textBox.getText();
                   recievedInput = true;
         public String getInput() {
              while(recievedInput == false) {
                   try {
                        Thread.sleep(2000);  //I  DONT want to do this!!
                   catch(InterruptedException e) {
                        e.printStackTrace();
              recievedInput = false;
              return inputText;
         private void setupGUI() {
              textBox.setMinimumSize(new Dimension(100, 20));
              input.addActionListener(buttonAction);
              this.getContentPane().setLayout(new BorderLayout());
              this.getContentPane().add(textBox, BorderLayout.WEST);
              this.getContentPane().add(input, BorderLayout.EAST);
              this.pack();
              this.setSize(100,300);
              this.setVisible(true);
    }If you have any ideas, I would greatly appreciate it

    warnerja,
    I tried the following, but I got an exception.
    in the while loop inside Client.java, I put the following:
                 synchronized(cg) {
                      try {
                          cg.wait();
                        fromUser = cg.getInput();
                      catch(InterruptedException e) {
                           e.printStackTrace();
                 }and inside my ClientGUI class, I put the following:
    private ActionListener buttonAction = new ActionListener() {
              public void actionPerformed(ActionEvent e)  {
                   inputText = textBox.getText();
                   ClientGUI.this.notify();
         public String getInput() {
              return inputText;
         }But I got this exception:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException: current thread not owner
         at java.lang.Object.notify(Native Method)
         at ClientGUI$1.actionPerformed(ClientGUI.java:21)
    any idea what I am doing wrong?

  • Problem using repaint() method from another class

    I am trying to make tower of hanoi...but unable to transfer rings from a tower to another...i had made three classes....layout21 where all componentents of frame assembled and provided suitable actionlistener.....second is mainPanel which is used to draw the rods n rings in paintComponent.....and third is tower in which code for hanoi is available...i had made an object of mainPanel at layoout21 n tower but i m not able to call repaint from tower..gives an error : cannot find the symbol....method repaint in tower.
    code fragments od three classes are:
    LAYOUT21
    class layout21 extends JFrame implements ActionListener
    { private Vector rod1 = new Vector();
    private Vector rod2 = new Vector();
    private Vector rod3 = new Vector();
    private String elem; //comment
    public String r22;
    public boolean in=false;
    public int count=0; //no of times the transfer to other rods performed
    private int r3,rings; // current no of rings
    private JComboBox nor,col;
    private JLabel no;
    private JLabel moved;
    private JLabel no1;
    private JButton start;
    private JButton ref;
    private AboutDialog dialog;
    private JMenuItem aboutItem;
    private JMenuItem exitItem;
    private tower t;
    final mainPanel2 p =new mainPanel2();
    public layout21()
    { t = new tower();
         Toolkit kit =Toolkit.getDefaultToolkit();
    Image img = kit.getImage("java.gif");
    setIconImage(img);
    setTitle("Tower Of Hanoi");
    setSize(615,615);
    setResizable(false);
    setBackground(Color.CYAN);
         JMenuBar mbar = new JMenuBar();
    setJMenuBar(mbar);
    JMenu fileMenu = new JMenu("File");
    mbar.add(fileMenu);
    aboutItem = new JMenuItem("About");
    aboutItem.addActionListener(this);
    fileMenu.add(aboutItem);
    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);
    Container contentPane =getContentPane();
    JPanel bspanel = new JPanel();
    JPanel bnpanel = new JPanel();
    setBackground(Color.CYAN);
         //JComboBox
    nor = new JComboBox();
    nor.setEditable(false);
    nor.addItem("3");
    nor.addItem("4");
    nor.addItem("5");
    nor.addItem("6");
    nor.addItem("7");
    nor.addItem("8");
    nor.addItem("9");
    bspanel.add(nor);
    col = new JComboBox();
    col.setEditable(false);
    col.addItem("BLACK");
    col.addItem("GREEN");
    col.addItem("CYAN");
    bspanel.add(col);
    JLabel tl = new JLabel("Time");
    tl.setFont(new Font("Serif",Font.BOLD,12));
    bspanel.add(tl);
    JTextField tlag = new JTextField("0",4);
    bspanel.add(tlag);
    start =new JButton("Start");
    bspanel.add(start);
    ref =new JButton("Refresh");
    bspanel.add(ref);
    JButton end =new JButton("End");
    bspanel.add(end);
    start.addActionListener(this);
    nor.addActionListener(this);
    col.addActionListener(this);
    ref.addActionListener(this);
    end.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    dispose(); // Closes the dialog
    contentPane.add(bspanel,BorderLayout.SOUTH);
    JLabel count = new JLabel("No of Transfer reguired:");
    count.setFont(new Font("Serif",Font.BOLD,16));
    bnpanel.add(count);
    no = new JLabel("7");
    no.setFont(new Font("Serif",Font.BOLD,16));
    bnpanel.add(no);
    JLabel moved = new JLabel("Moved:");
    moved.setFont(new Font("Serif",Font.BOLD,16));
    bnpanel.add(moved);
    no1 = new JLabel("0");
    no1.setFont(new Font("Serif",Font.BOLD,16));
    bnpanel.add(no1);
    contentPane.add(bnpanel,BorderLayout.NORTH);
    contentPane.add(p,BorderLayout.CENTER);
         String r = (String)nor.getSelectedItem();
    rings = Integer.valueOf(r).intValue();
    p.draw(rings,1) ;
    public void actionPerformed(ActionEvent evt)
    {  Object source = evt.getSource();
    if(source == start)
    r3 = Integer.valueOf((String)nor.getSelectedItem()).intValue();
    p.transfer(false);
    t.initialise(rod1,rod2,rod3,0);
    t.towerOfHanoi(r3);
         //repaint();
         if(source == ref)
    { rod1.removeAllElements() ;
    rod2.removeAllElements() ;
    rod3.removeAllElements() ;
    count=0;
              r3 = Integer.valueOf((String)nor.getSelectedItem()).intValue();
              p.draw(r3,1);
    p.transfer(true);
    no1.setText(""+0);
    p.trans_vec(rod1,rod2,rod3);
    t.initialise(rod1,rod2,rod3,0);
              System.out.println("");
              repaint();
    if(source == nor)
    { JComboBox j = (JComboBox)source;
    String item = (String)j.getSelectedItem();
    int ring1 = Integer.valueOf(item).intValue();
    int a=1;
    for(int i=1;i<=ring1;i++)
    { a = a*2;
    a=a-1;
    no.setText(""+a);
    p.draw(ring1,1);
    repaint();
    if(source == aboutItem)
    {  if (dialog == null) // first time
    dialog = new AboutDialog(this);
    dialog.setVisible(true);
    if(source == exitItem)
    {  System.exit(0);
         if (source==col)
         { JComboBox j = (JComboBox)source;
    String item = (String)j.getSelectedItem();
              repaint();
    TOWER
    class tower extends Thread
    { private Vector rod1 = new Vector();
    private Vector rod2 = new Vector();
    private Vector rod3 = new Vector();
    private int count ;
    private String elem;
    final mainPanel2 z =new mainPanel2();
    public void initialise(Vector r1,Vector r2,Vector r3,int c)
    { rod1 = r1;
    rod2 = r2;
         rod3 = r3;
         count =c;
    public void towerOfHanoi(int rings)
    for(int i=0;i<rings;i++)
    rod1.add(" "+(i+1));
    System.out.println("rod1:"+rod1.toString());
    hanoi(rings,1,2);
    public void hanoi(int m,int i, int j)
    if(m>0)
    { hanoi(m-1,i,6-i-j);
    if(i==1 && j==2 && rod1.isEmpty()==false)
    { count++;
    //no1.setText(""+count);
    elem = (String)rod1.remove(0);
    rod2.add(0,elem);
         //z.trans_vec(rod1,rod2,rod3);
    repaint(); //NOT ABLE TO USE METHOD HERE...WHY??
    //z.hanoi_paint();
    try
              this.sleep(2000);      
              catch (Exception e) { e.printStackTrace() ;  }
    System.out.println(count+". ROD 2:"+rod2.toString());
    if(i==1 && j==3 && rod1.isEmpty()==false)
    { count++;
         //no1.setText(""+count);
         elem = (String)rod1.remove(0);
    rod3.add(0,elem);
    //z.trans_vec(rod1,rod2,rod3);
    repaint();//
    // z.hanoi_paint();
                   try
              this.sleep(2000);      
              catch (Exception e) { e.printStackTrace() ;  }
    System.out.println(count+". ROD 3:"+rod3.toString());
    if(i==2 && j==1 && rod2.isEmpty()==false)
    { count++;
         //no1.setText(""+count);
         elem = (String)rod2.remove(0);
    rod1.add(0,elem);
    //z.trans_vec(rod1,rod2,rod3);
    repaint();
    //z.hanoi_paint();
    try
              this.sleep(2000);      
              catch (Exception e) { e.printStackTrace() ;  }
    System.out.println(count+". ROD 1:"+rod1.toString());
    if(i==2 && j==3 && rod2.isEmpty()==false)
    { count++;     
         //no1.setText(""+count);
         elem = (String)rod2.remove(0);
    rod3.add(0,elem);
    //z.trans_vec(rod1,rod2,rod3);
    repaint();
    //z.hanoi_paint();
    try
              this.sleep(2000);      
              catch (Exception e) { e.printStackTrace() ;  }
    System.out.println(count+". ROD 3:"+rod3.toString());
    if(i==3 && j==1 && rod3.isEmpty()==false)
    { count++;
         //no1.setText(""+count);
    elem = (String)rod3.remove(0);
    rod1.add(0,elem);
    //z.trans_vec(rod1,rod2,rod3);
    repaint();
    //z.hanoi_paint();
         try
              this.sleep(2000);      
              catch (Exception e) { e.printStackTrace() ;  }
    System.out.println(count+". ROD 1:"+rod1.toString());
    if(i==3 && j==2 && rod3.isEmpty()==false)
    { count++;
         //no1.setText(""+count);
    elem = (String)rod3.remove(0);
    rod2.add(0,elem);
    //z.trans_vec(rod1,rod2,rod3);
    repaint();
    //z.hanoi_paint();
    try
              this.sleep(2000);      
              catch (Exception e) { e.printStackTrace() ;  }
    System.out.println(count+". ROD 2:"+rod2.toString());
    hanoi(m-1,6-i-j,j);
    MAINPANEL
    class mainPanel2 extends JPanel //throws IOException
    public Vector line = new Vector();
    public Vector rod11= new Vector();
    public Vector rod22= new Vector();
    public Vector rod33= new Vector();
    public int no_ring;
    public int rod_no;
    String pixel;
    StringTokenizer st,st1;
    int x,y;
    public boolean initial =true;
    public void paintComponent(Graphics g)
    { System.out.println("repaint test");
    bresenham(100,60,100,360);
         bresenham(101,60,101,360);
    bresenham(102,60,102,360);
    bresenham(103,60,103,360);
    bresenham(104,60,104,360);     
    g.setColor(Color.BLUE);
    while(line.size()>0)
    { pixel = (String)line.remove(0);
    st = new StringTokenizer(pixel);
    x = Integer.valueOf(st.nextToken()).intValue();
    y = Integer.valueOf(st.nextToken()).intValue();
    g.drawLine(x,y,x,y);
    bresenham(300,60,300,360);
    bresenham(301,60,301,360);
    bresenham(302,60,302,360);
    bresenham(303,60,303,360);
    bresenham(304,60,304,360);     
    while(line.size()>0)
    { pixel = (String)line.remove(0);
    st = new StringTokenizer(pixel);
    x = Integer.valueOf(st.nextToken()).intValue();
    y = Integer.valueOf(st.nextToken()).intValue();
    g.drawLine(x,y,x,y);
    bresenham(500,60,500,360);
    bresenham(501,60,501,360);
    bresenham(502,60,502,360);
    bresenham(503,60,503,360);
    bresenham(504,60,504,360);     
    while(line.size()>0)
    { pixel = (String)line.remove(0);
    st = new StringTokenizer(pixel);
    x = Integer.valueOf(st.nextToken()).intValue();
    y = Integer.valueOf(st.nextToken()).intValue();
    g.drawLine(x,y,x,y);
    bresenham(0,361,615,361);//used to get a pixel according to algo.. . func not provided
    bresenham(0,362,615,362);
    bresenham(0,363,615,363);
    bresenham(0,364,615,364);
    bresenham(0,365,615,365);     
    while(line.size()>0)
    { pixel = (String)line.remove(0);
    st = new StringTokenizer(pixel);
    x = Integer.valueOf(st.nextToken()).intValue();
    y = Integer.valueOf(st.nextToken()).intValue();
    g.drawLine(x,y,x,y);
    if(initial==true)
    g.setColor(Color.RED);
    for(int i = no_ring;i>0;i--)
    { g.drawLine(100-(i*8),360-(no_ring - i)*10,100+(i*8)+5,360-(no_ring - i)*10);
    g.drawLine(100-(i*8),359-(no_ring - i)*10,100+(i*8)+5,359-(no_ring - i)*10);
    g.drawLine(100-(i*8),358-(no_ring - i)*10,100+(i*8)+5,358-(no_ring - i)*10);
    g.drawLine(100-(i*8),357-(no_ring - i)*10,100+(i*8)+5,357-(no_ring - i)*10);
    g.drawLine(100-(i*8),356-(no_ring - i)*10,100+(i*8)+5,356-(no_ring - i)*10);
    // draw for each rod
    //System.out.println("rod11:"+rod11);
    //System.out.println("rod22:"+rod22);
    //System.out.println("rod33:"+rod33);
         int r1 = rod11.size();
         int r2 = rod22.size();
         int r3 = rod33.size();
    String rd1,rd2,rd3;
    int r11,r12,r21,r22,r31,r32;
    if(initial == false)
         { g.setColor(Color.RED);
         while(rod11.size()>0)
    { r12 = rod11.size()-1;
              rd1 = (String)rod11.remove(r12);
    r11 = Integer.valueOf(rd1).intValue();
    g.drawLine(100-((r11+1)*8),360-(r1 - (r11+1))*10,100+((r11+1)*8)+5,360-(r1 - (r11+1))*10);
    g.drawLine(100-((r11+1)*8),359-(r1 - (r11+1))*10,100+((r11+1)*8)+5,359-(r1 - (r11+1))*10);
              g.drawLine(100-((r11+1)*8),358-(r1 - (r11+1))*10,100+((r11+1)*8)+5,358-(r1 - (r11+1))*10);
              g.drawLine(100-((r11+1)*8),357-(r1 - (r11+1))*10,100+((r11+1)*8)+5,357-(r1 - (r11+1))*10);
              g.drawLine(100-((r11+1)*8),356-(r1 - (r11+1))*10,100+((r11+1)*8)+5,356-(r1 - (r11+1))*10);
         while(rod22.size()>0)
    { g.setColor(Color.RED);
              r22 = rod22.size()-1;
         System.out.println("TEST *************************:"+r22);
              try
         // e.printStackTrace();      
              InputStreamReader isr = new InputStreamReader(System.in);
         BufferedReader br = new BufferedReader(isr)      ;
         br.readLine() ;
         }catch(Exception f) {}
              rd2 = ((String)rod22.remove(r22)).trim();
    r21 = Integer.valueOf(rd2).intValue();
    g.drawLine(300-((r22+1)*8),360-(r2 - (r22+1))*10,300+((r22+1)*8)+5,360-(r2 - (r22+1))*10);
    g.drawLine(300-((r22+1)*8),359-(r2 - (r22+1))*10,300+((r22+1)*8)+5,359-(r2 - (r22+1))*10);
              g.drawLine(300-((r22+1)*8),358-(r2 - (r22+1))*10,300+((r22+1)*8)+5,358-(r2 - (r22+1))*10);
              g.drawLine(300-((r22+1)*8),357-(r2 - (r22+1))*10,300+((r22+1)*8)+5,357-(r2 - (r22+1))*10);
              g.drawLine(300-((r22+1)*8),356-(r2 - (r22+1))*10,300+((r22+1)*8)+5,356-(r2 - (r22+1))*10);
         while(rod33.size()>0)
    { g.setColor(Color.RED);
              r32 = rod33.size()-1;
              rd3 = (String)rod33.remove(r32);
    r31 = Integer.valueOf(rd3).intValue();
    g.drawLine(500-((r32+1)*8),360-(r3 - (r32+1))*10,500+((r32+1)*8)+5,360-(r3 - (r32+1))*10);
    g.drawLine(500-((r32+1)*8),359-(r3 - (r32+1))*10,500+((r32+1)*8)+5,359-(r3 - (r32+1))*10);
              g.drawLine(500-((r32+1)*8),358-(r3 - (r32+1))*10,500+((r32+1)*8)+5,358-(r3 - (r32+1))*10);
              g.drawLine(500-((r32+1)*8),357-(r3 - (r32+1))*10,500+((r32+1)*8)+5,357-(r3 - (r32+1))*10);
              g.drawLine(500-((r32+1)*8),356-(r3 - (r32+1))*10,500+((r32+1)*8)+5,356-(r3 - (r32+1))*10);
    why i m not able to use repaint() method in tower class? from where i can use repaint() method

    i can't read your code - not formatted with code tags
    I have no chance of getting it to compile (AboutDialog class?? p.draw() ??)
    here's a basic routine - add a couple of things to this to demonstrate what is not
    being redrawn
    (compare the readability of below code (using tags) to yours)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setSize(400,300);
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        final DrawPanel dp = new DrawPanel();
        JButton btn = new JButton("Change Text Location/Repaint");
        getContentPane().add(dp,BorderLayout.CENTER);
        getContentPane().add(btn,BorderLayout.SOUTH);
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            dp.x = (int)(Math.random()*300);
            dp.y = (int)(Math.random()*150)+50;
            repaint();}});
      public static void main(String[] args){new Testing().setVisible(true);}
    class DrawPanel extends JPanel
      int x = 50, y = 50;
      public void paintComponent(Graphics g)
        super.paintComponent(g);
        g.drawString("Hello World",x,y);
    }

  • How to call a method of another class ?

    Hello,
    I�d like to know how to call a method of another class. I have to classes (class 1 and class 2), class 1 instantiates an object of class 2 and executes the rest of the method. Later, class 1 has to call a method of class 2, sending a message to do something in the object... Does anybody know how to do that ? Do I have to use interface ? Could you please help me ?
    Thanks.
    Bruno.

    Hi Schiller,
    The codes are the following:
    COMECO
    import javax.swing.UIManager;
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.*;
    //Main method
    class comeco {
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception e) {
    AGORA testeagora=new AGORA();
    // Code for socket
    int port;
         ServerSocket server_socket;
         BufferedReader input;
         try {
         port = Integer.parseInt(args[0]);
         catch (Exception e) {
         System.out.println("comeco ---> port = 1500 (default)");
         port = 1500;
         try {
         server_socket = new ServerSocket(port);
         System.out.println("comeco ---> Server waiting for client on port " +
                   server_socket.getLocalPort());
         // server infinite loop
         while(true) {
              Socket socket = server_socket.accept();
              System.out.println("comeco ---> New connection accepted " +
                        socket.getInetAddress() +
                        ":" + socket.getPort());
              input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
              // print received data
              try {
              while(true) {
                   String message = input.readLine();
                   if (message==null) break;
                   System.out.println("comeco ---> " + message);
    testeagora.teste(message);
              catch (IOException e) {
              System.out.println(e);
              // connection closed by client
              try {
              socket.close();
              System.out.println("Connection closed by client");
              catch (IOException e) {
              System.out.println(e);
         catch (IOException e) {
         System.out.println(e);
    AGORA
    import javax.swing.UIManager;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import java.net.*;
    //public class AGORA {
    public class AGORA {
    boolean packFrame = false;
    //Construct the application
    public AGORA() {
    try {
    Main frame = new Main();
    System.out.println("agora ---> Criou o frame");
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame)
    frame.pack();
    else
    frame.validate();
    //Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height)
    frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width)
    frameSize.width = screenSize.width;
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);
    catch(Exception e)
    { System.out.println("agora ---> " +e);
    // Tem que criar a THREAD e ver se funciona
    public void remontar (final String msg) {
    try {
                   System.out.println("agora ---> Passou pelo Runnable");
    System.out.println("agora --> Mensagem que veio do comeco para agora: "+ msg);
    Main.acao(msg);
    catch(Exception x) {
    x.printStackTrace();
    MAIN
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import javax.swing.border.*;
    import java.net.*;
    import java.io.*;
    public class Main extends JFrame {
    // ALL THE CODE OF THE INTERFACE
    //Construct the frame
    public Main() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public void acao() {
    // C�digo para mudar a interface
    Runnable setTextRun=new Runnable() {
    public void run() {
    try {
                   System.out.println("main ---> Passou pelo Runnable");
    TStatus.setText("main ---> Funcionou");
    catch(Exception x) {
    x.printStackTrace();
    System.out.println("main ---> About to invokelater");
    SwingUtilities.invokeLater(setTextRun);
    System.out.println("main ---> Back from invokelater");
    // Aqui vai entrar o m�todo para ouvir as portas sockets.
    // Ele deve ouvir e caso haja alguma nova mensagem, trat�-la para
    // alterar as vari�veis e redesenhar os pain�is
    // Al�m disso, o bot�o de refresh deve aparecer ativo em vermelho
    //Component initialization
    private void jbInit() throws Exception {
    // Initialize the interface
    //Setting | Host action performed
    public void SetHost_actionPerformed(ActionEvent e) {
         int port;
         ServerSocket server_socket;
         BufferedReader input;
    System.out.println("main ---> port = 1500 (default)");
         port = 1500;
         try {
         server_socket = new ServerSocket(port);
         System.out.println("main ---> Server waiting for client on port " +
                   server_socket.getLocalPort());
         // server infinite loop
    while(true) {
              Socket socket = server_socket.accept();
              System.out.println("main ---> New connection accepted " +
                        socket.getInetAddress() +
                        ":" + socket.getPort());
              input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String espaco=new String(": ");
         JLabel teste2=new JLabel(new ImageIcon("host.gif"));
              PHost.add(teste2);
    System.out.println("main ---> Adicionou host na interface");
              repaint();
    System.out.println("main ---> Redesenhou a interface");
              setVisible(true);
              // print received data
              try {
              while(true) {
                   String message = input.readLine();
                   if (message==null) break;
                   System.out.println("main ---> " + message);
              catch (IOException e2) {
              System.out.println(e2);
              // connection closed by client
              try {
              socket.close();
              System.out.println("main ---> Connection closed by client");
              catch (IOException e3) {
              System.out.println(e3);
         catch (IOException e1) {
         System.out.println(e1);
    public void OutHost_actionPerformed(ActionEvent e) {
              repaint();
              setVisible(true);
    //Help | About action performed
    public void helpAbout_actionPerformed(ActionEvent e) {
    Main_AboutBox dlg = new Main_AboutBox(this);
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = getSize();
    Point loc = getLocation();
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setModal(true);
    dlg.show();
    //Overridden so we can exit on System Close
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
    fileExit_actionPerformed(null);
    public void result(final String msg) {
    // C�digo para mudar a interface
    Runnable setTextRun=new Runnable() {
    public void run() {
    try {
                   System.out.println("main ---> Chamou o m�todo result para mudar a interface");
    System.out.println("main --> Mensagem que veio do agora para main: "+ msg);
    TStatus.setText(msg);
    catch(Exception x) {
    x.printStackTrace();
    System.out.println("main --> About to invokelater");
    SwingUtilities.invokeLater(setTextRun);
    System.out.println("main --> Back from invokelater");
    []�s.

  • DataInputStream: method readLine() is deprecated. (What's the alternative?)

    Hi there,
    I have a DataInputStream object (code below). The code works great but I get a warning message below the code: dis.readLine()
    The method readLine() from the type DataInputStream is deprecated
    does anyone have an alternative to eliminate the warning?
    DataInputStream dis = null;
    String line = null;
    //read
    File f = new File(inputFolder+"/"+inputFileName);
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis); 
    while ( (line=dis.readLine()) != null )
    }

    http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInputStream.html
    readLine()
    Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:
    DataInputStream d = new DataInputStream(in);
    with:
    BufferedReader d
    = new BufferedReader(new InputStreamReader(in));

  • "Open method of Workbooks class failed" when opening Excel file via Internet Explorer

    (apologies, I posted this first to the general Office 2010 forum, but then realized this was probably a better spot to post)
    We have an Excel COM add-in installed on users' PCs.  This add-in responds to workbook open events by opening a particular XLA file (also deployed to the PC) to make certain features available.  This process works flawlessly when Excel files are
    opened locally - but when a user attempts to open an Excel file from an IE link, we get the following error: "Open method of Workbooks class failed".  This is happening on the line that is trying to open the XLA file.  This only happens
    when launching an Excel link from IE - works fine in Chrome or Firefox.
    I have found several posts on this topic, but no solutions:
    1. This post (https://social.msdn.microsoft.com/forums/office/en-US/73c96005-84af-4648-b103-32b677205be3/open-method-of-workbooks-class-failed)
    is the closest to our problem.  In this case, the "answer" was that the user may not have access to the 2nd workbook being opened.  But in our case, we're opening an XLA that is on the local machine, and I've confirmed that it is not
    corrupt and accessible (read & write, just in case!) to Everyone.
    2. This (very old) post (http://www.pcreview.co.uk/forums/open-method-workbooks-fails-excel-hosted-ie-t965608.html)
    seems similar, but is talking about opening Excel inside of IE.  This is not what we're doing - the link is supposed to (and does) open Excel outside of IE.  Interestingly, Excel.exe is being launched with the "-embedded" flag, even
    though it isn't running in the IE window.  When launching Excel by opening the file locally, Excel.exe is run with the "/dde" flag instead.  Clearly the "-embedded" mode is what is causing the problem.  I could change the
    links on the web page to use some JavaScript to open Excel differently... unfortunately, the links are actually generated by SharePoint (the Excel files are in a SP repository), so this is not really an option.
    3. This Microsoft KB article (http://support.microsoft.com/kb/268016) talks about problems opening an XLA directly from IE... but this is the case of a link pointing
    directly to an XLA file, not opening a regular workbook that in turn opens an XLA, as is my case.  In fact, this article specifically points out in the "More Information" section that "End users do not normally open XLAs; instead they open
    an XLS that (if needed) loads one or more XLAs during startup." ==> precisely what I'm trying to do that is giving me the error!
    I've replicated the situation with a very simple COM add-in (created in VS2010 using VB.Net) and a very simple XLA file (does nothing, just pops up a message in auto_open).  For anyone wanting to try it out, here is the exact test case:
    1. In Excel, create a simple XLA file containing only the following code, and save it in C:\TEMP\dummy.xla:
    Sub Auto_Open()
    MsgBox "Auto Open fired"
    End Sub
    2. In Visual Studio, create a new Excel 2010 Add-In.  I created mine via Visual Basic, but I doubt the choice of language matters.  Place the following code in ThisAddin.vb:
    Public Class ThisAddIn
    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    AddHandler Me.Application.WorkbookOpen, AddressOf Application_WorkbookOpen
    End Sub
    Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
    End Sub
    Sub Application_WorkbookOpen(ByVal workbook As Excel.Workbook)
    On Error GoTo ErrHandler
    If (Not workbook.Name.Contains("dummy.xla")) Then
    MsgBox("Workbook open")
    Application.Workbooks.Open("C:\temp\dummy.xla")
    Application.Workbooks("dummy.xla").RunAutoMacros(Excel.XlRunAutoMacro.xlAutoOpen)
    End If
    Exit Sub
    ErrHandler:
    MsgBox(Err.Description)
    End Sub
    End Class
    3. Build & publish this add-in and install it on the same machine as the XLA created in step 1.
    4. Create and save an empty Excel workbook (I called mine WayneTest1.xlsx) - save it locally (on your desktop), and put a copy somewhere on your web server (I put mine directly in c:\inetpub).
    5. Create an HTML file with a link to that workbook, saving it to the same web server location - here is mine:
    <html>
    <body>
    <a href="WayneTest1.xlsx">Link to Excel file</a>
    </body>
    </html>
    6. Double click the workbook on your desktop (from step 4) - opens fine, I get the "workbook open" message, following by the "Auto Open fired" message.
    7. In Internet Explorer, navigate to the HTML file specified in step 5 and click on the link - when prompted, select "Open" - I get the "workbook open" message, following by the error message "Open method of Workbooks class failed".
    Here are a few things I've ruled out / tried so far:
    - Unchecked all the "Protected View" settings in Excel, made no difference
    - Unchecked all the "File block settings" in Excel, made no difference
    - Made sure dummy.xla was open for read & write to Everyone
    - Made sure the web page was in Trusted sites and set the security level to Low for those sites in IE
    - Tried making the local desktop file (step 6) readonly, made no difference (i.e. launching it locally still worked fine)
    - Tried using Excel 2013 - made no difference
    Any ideas / suggestions?

    Hello Wayne,
    Apologies for the delay.
    I went through your post and tried to reproduce the issue. I was able to reproduce it. Based
    on its complexity and as it requires more in-depth analysis, your question falls into the paid support category which requires a more in-depth level of support.
    Please visit the below link to see the various paid support options that are
    available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
    Thanks,
    Anush

  • Error: The method ReadLine() is undefined for the typ of Objectkey.

    I'm new at Java. Can anyone help??? Much appreciated.
    public class readfilesAppd {
    //     /define string newline for line.seperator
       private static final String nl = System.getProperty("line.separator");
          private static final String userpath = System.getProperty("C:/Documents and Settings/GheeL/My Documents/My Data/835 ERA files/");
          // public static void main(String[] args, Object fr) {
         public static void main(String [] args) {
                     try {
                          ObjectKey br = null;
         //struct stat request_stat_path(char C:/Documents and Settings/GheeL/My Documents/My Data/835 ERA files/, Request *rq);
                // Create file
                //FileReader fr = new FileReader("C:/Documents and Settings/GheeL/My Documents/My Data/835 ERA files/");               
                //String FILENAME = "";
                 String FILENAME = userpath;
                String record = new String();
                         int recCount = 0; 
                        while ((record = br.ObjectKey())) != null)
                               recCount++;
                                FILENAME = record.substring(780, 792);
                              FileWriter fstream = new FileWriter("ERA Loads.txt", true);
                               BufferedWriter out = new BufferedWriter(fstream);
                               out.write(FILENAME+" "+recCount);
                               out.close();
                               System.out.println(FILENAME);
                               System.out.println(recCount);
                          catch (Exception e){//Catch exception if any
                              System.err.println("Error: " + e.getMessage());           
                        finally {
                     System.out.println("Is that something to cheer about?");
                             }

    You haven't posted the correct code. The error is telling you that you're trying to call a method "ReadLine()" on an object that doesn't have a method by that name. The code you posted doesn't call anything called ReadLine(). Find the code where that happens and post it.

  • Synchronisation methods in same class

    I have three methods in same class A,B,C IN which A,B synchronised and c not.
    my question is if one thread is in A.another thread cann access B OR C?

    jverd wrote:
    Syncing a block on the object pointed to by X
    synchronized (X) { /* do stuff */}simply waits until no other thread is synced on that object, and then enters the block.
    Declaring a non-static method synchronized is the same as doing synchronized (this) { /* do stuff */ }Calling a non-synced method or executing a non-synced block or statement does not wait for the lock.Duke-wh0ring?? :)

  • Reg - how to find the purpose of methods in a class

    hi everyone,
               can u plz help me with how to find the purpose of methods in a class???????
    a description abt the methods in a class??????
                        thx in advance,
    regards,
    balaji.s

    Hi Balaji
    Pls find some stuff.
    reward pts if help.
    The following statements define the structure of a class:
    ·        A class contains components
    ·        Each component is assigned to a visibility section
    ·        Classes implement methods
    The following sections describe the structure of classes in more detail.
    Class Components
    The components of a class make up its contents. All components are declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility sections, which define the external interface of the class. All of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class.
    There are two kinds of components in a class - those that exist separately for each object in the class, and those that exist only once for the whole class, regardless of the number of instances. Instance-specific components are known as instance components. Components that are not instance-specific are called static components.
    In ABAP Objects, classes can define the following components. Since all components that you can declare in classes can also be declared in interfaces, the following descriptions apply equally to interfaces.
    Attributes
    Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.
    Instance Attributes
    The contents of instance attributes define the instance-specific state of an object. You declare them using the DATAstatement.
    Static Attributes
    The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.
    All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.
    The technical properties of instance attributes belong to the static properties of a class. It is therefore possible to refer in a LIKE addition to the visible attributes of a class – through the class component selector or through reference variables, without prior creation of an object.
    Methods
    Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.
    The definition and parameter interface of a method is similar to that of function modules. You define a method meth in the definition part of a class and implement it in the implementation part using the following processing block:
    METHOD meth.
    ENDMETHOD.
    You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function modules). You call methods using the CALL METHOD statement.
    Instance Methods
    You declare instance methods using the METHODSstatement. They can access all of the attributes of a class, and can trigger all of the events of the class.
    Static Methods
    You declare static methods using the CLASS-METHODSstatement. They can only access static attributes and trigger static events.
    Special Methods
    As well as normal methods, which you call using CALL METHOD, there are two special methods called constructor and class_constructor that are automatically called when you create an object or when you first access the components of a class.
    reward pts if help.
    deepanker

  • Question about methods in a class that implements Runnable

    I have a class that contains methods that are called by other classes. I wanted it to run in its own thread (to free up the SWT GUI thread because it appeared to be blocking the GUI thread). So, I had it implement Runnable, made a run method that just waits for the thread to be stopped:
    while (StopTheThread == false)
    try
    Thread.sleep(10);
    catch (InterruptedException e)
    //System.out.println("here");
    (the thread is started in the class constructor)
    I assumed that the other methods in this class would be running in the thread and would thus not block when called, but it appears the SWT GUI thread is still blocked. Is my assumption wrong?

    powerdroid wrote:
    Oh, excellent. Thank you for this explanation. So, if the run method calls any other method in the class, those are run in the new thread, but any time a method is called from another class, it runs on the calling class' thread. Correct?Yes.
    This will work fine, in that I can have the run method do all the necessary calling of the other methods, but how can I get return values back to the original (to know the results of the process run in the new thread)?Easy: use higher-level classes than thread. Specifically those found in java.util.concurrent:
    public class MyCallable implements Callable<Foo> {
      public Foo call() {
        return SomeClass.doExpensiveCalculation();
    ExecutorService executor = Executors.newFixedThreadPool();
    Future<Foo> future = executor.submit(new MyCallable());
    // do some other stuff
    Foo result = future.get(); // get will wait until MyCallable is finished or return the value immediately when it is already done.

  • Help with calling methods of different classes

    I have two classes. In class A I read a line of input from the console
    myVar= x.readLine();
    then I call a method of the same class (A)
    methodA(); i get NULLPOINTEREXCEPTION here
    in this method I wish to call another method but this time of class B so I create an instance of class B in class A
    private B instanceVar;
    and then proceed to create the method call to class B
    instanceVar.methodB(myVar); i get NULLPOINTEREXCEPTION here
    What am I doing wrong?

    What am I doing wrong?Not posting a short snippet of java code that demonstrates your problem.
    In class A I read a line of input from the console
    myVar= x.readLine();
    How is that related to the NPE's?
    then I call a method of the same class (A)
    methodA(); i get NULLPOINTEREXCEPTION hereSomething is probably wrong in methodA(). Impossible to say anything more with the information given.
    private B instanceVar;
    and then proceed to create the method call to class B
    instanceVar.methodB(myVar); i get NULLPOINTEREXCEPTION hereDid you ever assign instanceVar to an actual object with something like instanceVar = new B(); ?

  • SaveAs Method Of Workbook Class Failed Upon fIntersectionCheckEx

    We are in the process of migrating from FDM and HFM 9.3.1 to 11.1.2.1. Because of the performance issues that we previously experienced with FDM's MultiLoad functionality, we've been using UD5 and UD6 and an adapter customization to load Year and Period. To accommodate the "extra" dimensions, we're also using custom Event scripts, check reports, etc.. The built-in intersection check is disabled. The AftValidate script contains our custom intersection check and follows below. When the Validate phase is executed from the web client, the following error appears in the log:
    ** Begin fdmFM11XG5E Runtime Error Log Entry [2011-10-13-12:03:15] **
    Error:
    Code............1004
    Description.....SaveAs method of Workbook class failed
    Procedure.......clsHPDataAccess.fIntersectionCheckEx
    Component.......C:\FDMData\fdm-hfm-adapter-V25481-01\FinancialDataManagement\FM11X-G5-E_1005\AdapterComponents\fdmFM11xG5E\fdmFM11XG5E.dll
    Version.........145
    Identification:
    User............larryr
    Computer Name...SVRHYPFDMV103
    FINANCIAL MANAGEMENT Connection:
    App Name........
    Cluster Name....
    Domain............
    Connect Status.... Connection Open
    ** Begin FDM Runtime Error Log Entry [2011-10-13 12:03:15] **
    ERROR:
    Code............................................. -2146233088
    Description...................................... SaveAs method of Workbook class failed
    At Line: 59
    Procedure........................................ clsEventHandler.PobjAPI_AftValidate
    Component........................................ upsWObjEventHandlerDM
    Version.......................................... 1112
    Thread........................................... 4828
    IDENTIFICATION:
    User............................................. larryr
    Computer Name.................................... SVRHYPFDMV103
    App Name......................................... SAPHFM
    Client App....................................... WebClient
    CONNECTION:
    Provider......................................... SQLOLEDB
    Data Server...................................... svrsql105
    Database Name.................................... SAPHFM
    Trusted Connect.................................. False
    Connect Status.. Connection Open
    GLOBALS:
    Location......................................... AHEL_F1
    Location ID...................................... 752
    Location Seg..................................... 6
    Category......................................... FctAug
    Category ID...................................... 16
    Period........................................... M12 - FY12
    Period ID........................................ 4/30/2012
    POV Local........................................ False
    Language......................................... 1033
    User Level....................................... 1
    All Partitions................................... True
    Is Auditor....................................... False
    ** Begin FDM Runtime Error Log Entry [2011-10-13 12:03:15] **
    ERROR:
    Code............................................. 440
    Description...................................... Automation error
    Procedure........................................ clsValidationMgr.fValidate
    Component........................................ upsWObjectsDM
    Version.......................................... 1112
    Thread........................................... 4828
    IDENTIFICATION:
    User............................................. larryr
    Computer Name.................................... SVRHYPFDMV103
    App Name......................................... SAPHFM
    Client App....................................... WebClient
    CONNECTION:
    Provider......................................... SQLOLEDB
    Data Server...................................... svrsql105
    Database Name.................................... SAPHFM
    Trusted Connect.................................. False
    Connect Status.. Connection Open
    GLOBALS:
    Location......................................... AHEL_F1
    Location ID...................................... 752
    Location Seg..................................... 6
    Category......................................... FctAug
    Category ID...................................... 16
    Period........................................... M12 - FY12
    Period ID........................................ 4/30/2012
    POV Local........................................ False
    Language......................................... 1033
    User Level....................................... 1
    All Partitions................................... True
    Is Auditor....................................... False
    Custom intersection check via AftValidate. Line 59 is fIntersectionCheckEx:
    Sub AftValidate(strLoc, strCat, strPer, lngProcState)
    'UpStream TB EVENT Script
    'Purpose:   Perform custom intersection check - customized for multiple periods
    Dim strTableName, strSQL'               Query variables
    Dim strPerYear, strPerMonth'          Target HFM Year & Month
    Dim strCatKey, strLocKey'               ID of POV Category & Location
    Dim strErr, strHTMFile'                    Error information
    Dim objHWReturn'                         Return object for intersection validation
    Dim objPeriod'                              Period object
    Dim fso'                                   File system object
    Dim rs'                                        Recordset containing unique HFM Target intersections
    Dim vaData'                                   Array containing unique HFM Target intersections
    ' Initialize Block Processor For HFM connection
    Dim BlOCKPROC
    Set BlOCKPROC = CreateObject("upsWBlockProcessorDM.clsBlockProcessor")
    BlOCKPROC.Initialize API, SCRIPTENG
    ' Call the Connect Action for the active integration block
    Set API.IntBlockMgr.IntegrationMgr.PobjIntegrate = BlOCKPROC.ActConnect("CheckDims")
    If API.IntBlockMgr.IntegrationMgr.PobjIntegrate.intResult Then' Connection is open
         'Get Target information
         strLocKey = CStr(RES.PlngLocKey)
         strPerKey = CStr(RES.PdtePerKey)
         strCatKey = CStr(RES.PlngCatKey)
         Set objPeriod = API.POVMgr.fPeriodKey(strPer)
         strPerYear = objPeriod.strTargetYear
         strPerMonth = objPeriod.strTarget
         Set objPeriod = Nothing
         strTableName = "tDataSeg" & API.POVMgr.fGetLocationSegment(strLocKey)' Get tDataSeg number for location
         strBaseName = strLoc & "_" & strCat & "_" & strPerMonth & "_" & strPerYear
         strLogsDir = DW.Connection.PstrDirOutbox & "\Logs\"
         strFile = strLogsDir & strBaseName & ".fmv"
         ' Create the SQL to pull the validation records
         ' Do not Validate the Keystone Custom2 records since their "parent" Classic Custom2 records are validated
         strSQL = "SELECT DISTINCT EntityX, PartitionKey, CatKey, PeriodKey, DataView, AccountX, ICPX, UD1X, UD2X, UD3X, UD4X," & _
                                         " '' AS UD5X, '' AS UD6X, '' AS UD7X, '' AS UD8X, '' AS UD9X, '' AS UD10X, '' AS UD11X," & _
                                       " '' AS UD12X, '' AS UD13X, '' AS UD14X, '' AS UD15X, '' AS UD16X, '' AS UD17X, '' AS UD18X," & _
                                       " '' AS UD19X, '' AS UD20X, '' AS Amt " & _
                    "FROM " &strTableName& " WITH (NOLOCK) " & _
                    "WHERE CatKey=" &strCatKey& " AND PeriodKey='" &strPerKey& "' AND PartitionKey=" &strLocKey
         'Validate all records in the result set
         Set rs = DW.DataAccess.farsFireHose(strSQL, False)
         With rs
              If Not .EOF Then' Create the array to pass to intersection checking
                   vaData = .GetRows(.RecordCount)
                   Set objHWReturn = API.IntBlockMgr.IntegrationMgr.PobjIntegrate.varCon.fIntersectionCheckEx(vaData, CStr(strCat), CStr(strPerMonth), CStr(strPerYear), "YTD", "<Entity Currency>", CStr(strFile), "FM Account", "FM Entity", "ICP", "Custom1", "Custom2", "Custom3", "Custom4", 15, 9, 2)
                   If objHWReturn.PblnIsErr Then
                        RES.PstrActionValue = objHWReturn.PstrErrFile
                        RES.PlngActionType = 4' Display HTML file on web client
                        API.MaintenanceMgr.mProcessLog strLoc, strCat, strPer, 2, False, "Custom Intersection Validation Error:  Error creating validation array", Now()
                   Else' Delete the html header file for the error free validation
                        strHTMFile = strLogsDir & strBaseName & ".htm"
                        Set fso = CreateObject("Scripting.FileSystemObject")
                        If fso.FileExists(strHTMFile) Then fso.DeleteFile strHTMFile, True
                        Set fso = Nothing
                   End If
                   Set objHWReturn = Nothing
              Else
                   strErr = "AftValidate Event Script error:  No data for intersection check" & vbCrLf
                   RES.PstrActionValue = strErr & "You must re-run the Import before running the Validate again"
                   RES.PlngActionType = 2' Display the error string
              End If
              .Close
         End With
         Set rs = Nothing
    End If
    'Destroy the remaining objects
    Set API.IntBlockMgr.IntegrationMgr.PobjIntegrate = Nothing
    Set BlOCKPROC = Nothing
    End Sub

    Thanks, Tony. I no longer get the "SaveAs method of Workbook class failed" error. Now, when there are intersection check errors, instead of the intersection check report automatically opening in a new tab, I get a "File Download" message box with Open and Save buttons. If I choose Open, I get the "404 - File or directory not found" error. If I choose Save and save the file to a local path, I never get the option to open the file and the "Processing. Please wait..." message runs forever.
    Per the FDM ReadMe, I've installed MSXML 3.0 SP7 on both the FDM server and client machines. I've set security to the lowest setting in IE 7.

  • Returning a HashMap K, M from a method of a class typed M

    So, this is what I have. I have a class parameterized for a bean type of a collection it receives, and in a method of the class, I need (would like) to return a HashMap typed as <K, M> as in:
    public class MyClass<M> {
       private Collection<M> beanList;
       public HashMap<K, M> getMap(  /* what do I do here */ );
    }I tried to cheat from looking at the Collections.sort method, knowing it uses the List type in its return type as in:
    public static <T extends Comparable<? super T>> void sort(List<T> list)So, I am trying:
    public HashMap<K, M> getMap(Class<K> keyType)But, it is telling me I need to create class K.
    So... how does the Collections.sort method get away with it and I can't????
    I suppose I could write the method as:
    public HashMap<Object, M> getMap()but became somewhat challenged by my first guess.
    Any ideas... or just go with the HashMap with the untyped key?

    ejp wrote:
    provided K is inferable from the arguments.Or from the assignment context:
    Set<String> empty = Collections.emptySet();
    Otherwise you have to parameterise the class on <K, M>.You may also specifically provide K when you use the method if the context doesn't give the compiler enough information or if you want to override it.
    Example:
    Set<Object> singleton1 = Collections.singleton("Hello"); //error
    Set<Object> singleton2 = Collections.<Object>singleton("Hello"); //fineEdited by: endasil on 14-May-2010 4:13 PM

  • Function Module to open a new session displaying a method of a class

    Hello All,
    I have a method A of class B.
    Now, in my current session, I have a button. When the user clicks on this button, what I expect is that a new session be opened and in the new session method A of class B be displayed.
    This is similar to the debugger, wherein, in the debugging mode, we can bring up the context menu in the Source Code (Edit Control) tool, and then select "Go To Source Code".
    So basically, I am looking for a Function Module which does the same.
    I came across Function Module CC_CALL_TRANSACTION_NEW_TASK, however, this will only create a new session.
    I could specify the transaction as SE24, but it then opens a new session with this transaction. That is it.
    My objective is to display the method of a class in a new session.
    Is there any Function Module in this case?
    Regards,
    Mithun
    Edited by: Mithun Kamath on Aug 9, 2011 5:35 PM

    Hello Sandra,
    Thank you very much. That was exactly what I was looking for.
    However, instead of calling EDITOR_PROGRAM directly, what I instea did was the following:
    1) Created a RFC enabled Function module.
    2) Inside this function module, I wrote the following code:
      SUBMIT tpda_editor_start AND RETURN
       WITH prgm  = is_alert_det-program_name
       WITH incl = is_alert_det-include_name
       WITH dynp = space
       WITH line = is_alert_det-line_no.
    The parameters above were similar to the one proposed by you.
    Borrowed the above from the class CL_TPDA_SERVICES_TOOLS, method NAVIGATE_TO_SOURCE.
    The above is basically called in the debugger, when we use the context menu in the editor tool and invoke the "Goto Source Code" functionality. This eventually calls the EDITOR_PROGRAM FM.
    The reason why I did this is because when I was testing the FM, it did not allow me to specify the include as CL_TEST=====CM01. I do not know why, probably I was doing it wrong. But it gave me a message saying that the object does not exist in table TADIR.
    Anyway, I did the above steps and it worked exactly as I wanted it to.
    I would like to thank you again.
    Best Regards,
    Mithun
    P.S. Forgot to add, I called the above RFC enabled FM as a new task.
    Edited by: Mithun Kamath on Aug 10, 2011 4:19 PM

  • How do i call the method in a class using servlet

    i am doing a project which need to use servlet to call a few methods in a class and display those method on the broswer. i tried to write the servlet myself but there are still some errors .. can anyone help:
    The servlet i wrote :
    package qm.minipas;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class test extends HttpServlet {
    Database database;
    /** Initializes the servlet.
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    database = FlatfileDatabase.getInstance();
    /** Destroys the servlet.
    public void destroy() {
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("this is my class wossname"+FlatfileDatabase.getInstance()); // this is calling the toString() method in the instance of myJavaClass
    out.println("this is my method"+FlatfileDatabase.getAll());
    out.println("</body>");
    out.println("</html>");
    out.close();
    /** Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
    return "Short description";
    my methods which i need to call are shown below:
    public Collection getAll() {
    return Collections.unmodifiableCollection(patientRecords);
    public Collection getInpatients() {
    Collection selection=new ArrayList();
    synchronized(patientRecords) {
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(next.isInpatient())
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByAdmissionDate(Date dateOfAdmission) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(dateOfAdmission.equals(next.getDateOfAdmission()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByAdmissionDates(Date from,Date to)
    throws IllegalArgumentException {
    if(to.before(from))
    throw new IllegalArgumentException("End date must not be before start date");
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    Date nextAD=next.getDateOfAdmission();
    if((nextAD.after(from)||nextAD.equals(from))
    &&(nextAD.before(to)||nextAD.equals(to)))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByDischargeDates(Date from,Date to)
    throws IllegalArgumentException {
    if(to.before(from))
    throw new IllegalArgumentException("End date must not be before start date");
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    Date nextAD=next.getDateOfDischarge();
    if(nextAD==null)
    continue;
    if((nextAD.after(from)||nextAD.equals(from))
    &&(nextAD.before(to)||nextAD.equals(to)))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByConsultant(String consultant) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(consultant.equalsIgnoreCase(next.getConsultant()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByDischargeDate(Date dateOfDischarge) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(dateOfDischarge.equals(next.getDateOfDischarge()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getBySurname(String surname) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(surname.equalsIgnoreCase(next.getSurname()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);
    public Collection getByWard(String ward) {
    List selection=new ArrayList();
    for(Iterator i=patientRecords.iterator(); i.hasNext();) {
    PatientRecord next=(PatientRecord) i.next();
    if(ward.equalsIgnoreCase(next.getWard()))
    selection.add(next);
    return Collections.unmodifiableCollection(selection);

    please provide a detail description of your errors.

Maybe you are looking for

  • No Receiver Agreement found - IDOC RCVPRN = Party

    Hello, I have created all the receiver agreements required and they are in the configuration scenario.  I have a receiver determination that is using the IDOC vendor number (RCVPRN) to determine the party for delivering purchase orders and another RD

  • How to redirect a page that does not exist

    Hello everyone. Thanks for the feedback so far. I am editing an old site and there are going to be some pages that do not exist anymore. Is there a way to have an automatic redirect so that if any user types in ANY page that does not exist sitewide,

  • How to get a form parameter and refresh the web web page itself?

    I thought its easy as a piece of cake. But what I found out is that somehow it is getting the parameter after the web page is refreshed! Any advice is greatly appreciated. Thanks! for navigation method    //navigation method     public Object refresh

  • New MBP won't back up, disc full

    I've searched around here and although I found similar question, never really found an answer: I have a new MacBookPro and want to use Time Machine to back it up. I get a message that there is insufficient space on my 1Gb TC. I thought it would autom

  • I can not download Icloud control panel!

    Windows Vista with Service Pack 2; download IE 9, downloaded icloud control panel and it says repair, then finish. Can not find that sucker anywhere! I need to sync with my new ipad for work! Please advice? Thank you.