Infinite loop in a catch {} statement, should be simple

Hi, I'm trying to take integer input from the console using a Java Scanner object, and I enter an infinite loop if there is an IO error inside the catch statement. Please let me know if you know what I'm doing wrong:
do
try
Problem = false; //this is a bool
start = Input.nextInt(); // Input is a Scanner, start is an Intenger
catch (Exception IOException) {
     Problem = true;
     System.out.println("Bad value.\n");
     //The infinite loop is inside this statement.
while (Problem == true);
This code block is intended to take integer input, then, if there's an IO error, try to do it again, indefinitely, until it has successfully given Start a value. As it stands, if executed, if there is not an IO error, it works; if there is an IO error it enters an infinite loop in the catch statement. Please forgive my incompetence, any help is appreciated :)

Hi, thanks for the advice to both of you, your suggestion that it is stuck seems to be correct.
I add to the catch statement:
Input = new Scanner(System.in);
To reset it, and it works now. This is probably not the best way to do things, but I'm just a student and it's for a homework assignment that does not require try / catch / for so it works for this, thank you for the help! :)

Similar Messages

  • Infinite Loop Question - should be simple

    Ok I think I have a simple question to ask here. I am attempting to create a program that creates an infinite loop for multiples of two...
    ex: 2, 4, 8, 16, etc...
    The math behind it is simple, x^2 when x = 2. I then want the result of each equation to be squared, and infinitely.
    Here is the code Ive written so far, I think Im close, but I may be way off... any hints or clues as to my next step would be appreciated.
    public class loopytest {
       public static void main (String[] args)
       int x = x^2;
       while (x = 2)
       System.out.println("Value of x is " + x);
    }

    int x = x^2;You have to initialise "x" first.
    You should give it an actual value (e.g. 2) for this case.
    int x = 2;If you want to get the value of x from arguments. (e.g. java YouProgram 2)
    You should change this part of code similar to the follow.
    int x = args[1];But this one hasn't used the Math.pow(), you should read the API and amend it.
    while (x = 2)This one is actually assign x with value 2.
    If you want to compare an int, you should use "A == B", "A.equals(B)" for Object.

  • Return statement should put beyond try/catch clause??

    The return statement should put beyond the try/catch clause, is that correct? Well,
    I tried to put inside the try block, but it will have compile error though.
    public String getValue()
         String value;
         try
         catch(...)
         return value;
    please advise. thanks!!

    When a method returns a value, you must make sure that even if an exception is thrown and caught a value will be returned (or just throw the exception out of the method).
    You can put a return clause as the last thing in the try block and another return clause after the catch block (this is where we go if we catch an exception so you probably want to return null).

  • Infinite loop error after using Java Sun Tutorial for Learning Swing

    I have been attempting to create a GUI following Sun's learning swing by example (example two): http://java.sun.com/docs/books/tutorial/uiswing/learn/example2.html
    In particular, the following lines were used almost word-for-word to avoid a non-static method call problem:
    SwingApplication app = new SwingApplication();
    Component contents = app.createComponents();
    frame.getContentPane().add(contents, BorderLayout.CENTER);I believe that I am accidentally creating a new instance of the gui class repeatedly (since it shows new GUI's constantly and then crashes my computer), possibly because I am creating an instance in the main class, but creating another instance in the GUI itself. I am not sure how to avoid this, given that the tutorials I have seen do not deal with having a main class as well as the GUI. I have googled (a nice new verb) this problem and have been through the rest of the swing by example tutorials, although I am sure I am simply missing a website that details this problem. Any pointers on websites to study to avoid this problem would be appreciated.
    Thanks for your time-
    Danielle
    /** GUI for MicroMerger program
    * Created July/06 at IARC
    *@ author Danielle
    package micromerger;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.swing.JFileChooser;
    import java.lang.Object;
    public class MGui
         private static File inputFile1, inputFile2;
         private static File sfile1, sfile2;
         private static String file1Name, file2Name;
         private String currFile1, currFile2;
         private JButton enterFile1, enterFile2;
         private JLabel enterLabel1, enterLabel2;
         private static MGui app;
         public MGui()
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        System.out.println("About to run create GUI method");
                        app = new MGui();
                        System.out.println("declared a new MGui....");
                        createAndShowGUI();
         //initialize look and feel of program
         private static void initLookAndFeel() {
            String lookAndFeel = null;
         lookAndFeel = UIManager.getSystemLookAndFeelClassName();
         try
              UIManager.setLookAndFeel(lookAndFeel);
         catch (ClassNotFoundException e) {
                    System.err.println("Couldn't find class for specified look and feel:"
                                       + lookAndFeel);
                    System.err.println("Did you include the L&F library in the class path?");
                    System.err.println("Using the default look and feel.");
                } catch (UnsupportedLookAndFeelException e) {
                    System.err.println("Can't use the specified look and feel ("
                                       + lookAndFeel
                                       + ") on this platform.");
                    System.err.println("Using the default look and feel.");
                } catch (Exception e) {
                    System.err.println("Couldn't get specified look and feel ("
                                       + lookAndFeel
                                       + "), for some reason.");
                    System.err.println("Using the default look and feel.");
                    e.printStackTrace();
         // Make Components--
         private Component createLeftComponents()
              // Make panel-- grid layout
         JPanel pane = new JPanel(new GridLayout(0,1));
            //Add label
            JLabel welcomeLabel = new JLabel("Welcome to MicroMerger.  Please Enter your files.");
            pane.add(welcomeLabel);
         //Add buttons to enter files:
         enterFile1 = new JButton("Please click to enter the first file.");
         enterFile1.addActionListener(new enterFile1Action());
         pane.add(enterFile1);
         enterLabel1 = new JLabel("");
         pane.add(enterLabel1);
         enterFile2 = new JButton("Please click to enter the second file.");
         enterFile2.addActionListener(new enterFile2Action());
         pane.add(enterFile2);
         enterLabel2 = new JLabel("");
         pane.add(enterLabel2);
         return pane;
         /** Make GUI:
         private static void createAndShowGUI()
         System.out.println("Creating a gui...");
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("MicroMerger");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         //Add stuff to the frame
         //MGui app = new MGui();
         Component leftContents = app.createLeftComponents();
         frame.getContentPane().add(leftContents, BorderLayout.WEST);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
    private class enterFile1Action implements ActionListener
         public void actionPerformed(ActionEvent evt)
              JFileChooser chooser = new JFileChooser();
              int rVal = chooser.showOpenDialog(enterFile1);
              if(rVal == JFileChooser.APPROVE_OPTION)
                   inputFile1 = chooser.getSelectedFile();
                   PrintWriter outputStream;
                   file1Name = inputFile1.getName();
                   enterLabel1.setText(file1Name);
    private class enterFile2Action implements ActionListener
         public void actionPerformed(ActionEvent evt)
              JFileChooser chooser = new JFileChooser();
              int rVal = chooser.showOpenDialog(enterFile1);
              if(rVal == JFileChooser.APPROVE_OPTION)
                   inputFile2 = chooser.getSelectedFile();
                   PrintWriter outputStream;
                   file2Name = inputFile2.getName();
                   enterLabel2.setText(file2Name);
    } // end classAnd now the main class:
    * Main.java
    * Created on June 13, 2006, 2:29 PM
    * @author Danielle
    package micromerger;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class Main
        /** Creates a new instance of Main */
        public Main()
         * @param args the command line arguments
        public static void main(String[] args)
            MGui mainScreen = new MGui();
            //mainScreen.setVisible(true);
            /**Starting to get file choices and moving them into GPR Handler:
             System.out.println("into main method");
         String file1Name = new String("");
             file1Name = MGui.get1Name();
         System.out.println("good so far- have MGui.get1Name()");
        }// end main(String[] args)
    }// end class Main

    um, yeah, you definitely have a recursion problem, that's going to create an infinite loop. you will eventually end up an out of memory error, if you don't first get the OS telling you you have too many windows. interestingly, because you are deferring execution, you won't get a stack overflow error, which you expect in an infinite recursion.
    lets examine why this is happening:
    in main, you call new MGui().
    new MGui() creates a runnable object which will be run on the event dispatch thread. That method ALSO calls new MGui(), which in turn ALSO creates a new object which will be run on the event dispatch thead. That obejct ALSO calls new MGui(), which ...
    well, hopefully you get the picture.
    you should never unconditionally call a method from within itself. that code that you have put in the constructor for MGui should REALLY be in the main method, and the first time you create the MGui in the main method as it currently exists is unnecessary.
    here's what you do: get rid of the MGui constructor altogether. since it is the implicit constructor anyway, if it doesn't do anything, you don't need to provide it.
    now, your main method should actually look like this:
    public static void main( String [] args ) {
      SwingUtilities.invokeLater( new Runnable() {
        public void run() {
          MGui app = new MGui();
          app.createAndShowGUI();
    }// end mainyou could also declare app and call the constructor before creating the Runnable, as many prefer, because you would have access to it from outside of the Runnable object. The catch there, though, is that app would need to be declared final.
    - Adam

  • Infinite loop - "Some actions taken while...offline could not be completed"

    I have 4 IMAP accounts (.Mac, Gmail and 2 at SpamArrest). Occasionally, I get in this infuriating state where I keep getting the following error:
    "Some actions taken while the account "ClickMarkets-SA" was offline could not be complete online.
    Mail has undone actions on some messages so that you can redo the actions while online. Mail has saved other message in mailbox "INBOX.Sent Messages" in "On My Mac" so that you can complete the
    actions while online.
    Additional information: The connection to the server "mail.spamarrest.com" on port 993 timed out."
    The only way I've found to resolve this infinite loop of messages (which subsequently backs up all other mail processing) is to quit mail, then cd to ~/Library/Mail/[email protected]/.OfflineCache and delete everything in there then relaunch mail.
    In each cases, I end up with a mailbox folder (Sent or Drafts) in the folder "On My Mac" which has one copy for each attempt at handling the message "online."
    I opened up the Connection Doctor and looked at the log details and saw that Mail is opening a socket to spamarrest and starting an APPEND operation on my INBOX.Drafts folder -- I have "store drafts on server" checked. It appears the APPEND operation is hanging and causing a timeout (see transcript below). This happens every 60 seconds. The error that I see after the timeout is:
    * BYE [ALERT] Fatal error: INTERNAL ERROR: Keyword hashtable memory corruption.: Input/output error
    Who's Fatal error is that?
    SpamArrest is trying to tell me the problem is with both of my computers and not their server. (Yes, this is hitting both my MacBook Pro and my iMac). Can anyone shed some more light on this? IMAP should be able to handle multiple computers so I don't see that as a problem. Is my Mail app not following protocol? Is it a filesystem issue (e.g. SpamArrest doesn't like the name of the folder)?
    Thanks.
    Chip
    Here is the log file segment:
    CONNECTED May 19 17:13:11.939 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1db74280
    READ May 19 17:13:12.266 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1db74280
    * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=CRAM-MD5 AUTH=PLAIN ACL ACL2=UNION] IMAP ready.
    WROTE May 19 17:13:12.301 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    1.785 LOGIN clickmarkets *******
    READ May 19 17:13:12.365 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    1.785 OK connected to proxy server.
    WROTE May 19 17:13:12.405 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    2.785 CAPABILITY
    READ May 19 17:13:12.463 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    * CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=CRAM-MD5 ACL ACL2=UNION
    2.785 OK CAPABILITY completed
    WROTE May 19 17:13:12.501 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    3.785 LIST "" ""
    READ May 19 17:13:12.561 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    * LIST (\Noselect) "." ""
    3.785 OK LIST completed
    WROTE May 19 17:13:12.616 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    4.785 APPEND "INBOX.Drafts (ClickMarkets-SA)" (\Seen \Draft $NotJunk NotJunk) "19-May-2009 17:07:30 -0700" {4525}
    READ May 19 17:13:13.627 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    + OK
    WROTE May 19 17:13:13.663 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    X-Uniform-Type-Identifier: com.apple.mail-draft
    From: Chip Roberson <[email protected]>
    To: "Charles S. Roberson" <[email protected]>
    X-Universally-Unique-Identifier: 155cc0fa-b377-4dd6-a5e6-d6563a23c711
    Subject: PM Test 1
    X-Apple-Auto-Saved: 1
    X-Apple-Mail-Remote-Attachments: YES
    X-Apple-Windows-Friendly: 1
    Message-Id: <[email protected]>
    Content-Type: text/html;
    charset=US-ASCII
    Content-Transfer-Encoding: quoted-printable
    Mime-Version: 1.0 (Apple Message framework v935.3)
    X-Apple-Base-Url: x-msg://85/
    Date: Tue, 19 May 2009 17:07:30 -0700
    X-Apple-Mail-Signature: 34D68E00-8E23-44FB-B72C-FFA86BB66FB3
    <html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
    -webkit-line-break: after-white-space; ">I'm starting to wonder if this =
    will ever fail when I need it to fail!<div><br><div =
    id=3D"AppleMailSignature"> <span class=3D"Apple-style-span" =
    style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
    Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
    font-weight: normal; letter-spacing: normal; line-height: normal; =
    orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; =
    white-space: normal; widows: 2; word-spacing: 0px; =
    -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =
    0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
    auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
    break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
    after-white-space; "><span class=3D"Apple-style-span" =
    style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
    Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
    font-weight: normal; letter-spacing: normal; line-height: normal; =
    orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
    widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
    -webkit-border-vertical-spacing: 0px; =
    -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
    auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
    break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
    after-white-space; "><span class=3D"Apple-style-span" =
    style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
    Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
    font-weight: normal; letter-spacing: normal; line-height: normal; =
    orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
    widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
    -webkit-border-vertical-spacing: 0px; =
    -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
    auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
    break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
    after-white-space; "><span class=3D"Apple-style-span" =
    style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
    Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
    font-weight: normal; letter-spacing: normal; line-height: normal; =
    orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
    widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
    -webkit-border-vertical-spacing: 0px; =
    -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
    auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
    break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
    after-white-space; "><span class=3D"Apple-style-span" =
    style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
    Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
    font-weight: normal; letter-spacing: normal; line-height: normal; =
    orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
    widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
    -webkit-border-vertical-spacing: 0px; =
    -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
    auto; -webkit-tex
    WROTE May 19 17:13:13.697 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    t-stroke-width: 0px; "><div style=3D"word-wrap: =
    break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
    after-white-space; ">--
    Chip =
    Roberson
    [email protected]
    http://www.linkedi=
    n.com/in/chiproberson
    =
    <br =
    class=3D"Apple-interchange-newline">
    </body></html>=
    READ May 19 17:14:13.626 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x189d0050 -- thread:0x1d314d10
    * BYE Disconnected for inactivity.
    * BYE [ALERT] Fatal error: INTERNAL ERROR: Keyword hashtable memory corruption.: Input/output error
    CONNECTED May 19 17:14:19.092 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x1db74280
    READ May 19 17:14:19.414 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x1db74280
    * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=CRAM-MD5 AUTH=PLAIN ACL ACL2=UNION] IMAP ready.
    WROTE May 19 17:14:19.449 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    1.786 LOGIN clickmarkets *******
    READ May 19 17:14:19.517 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    1.786 OK connected to proxy server.
    WROTE May 19 17:14:19.555 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    2.786 CAPABILITY
    READ May 19 17:14:19.622 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    * CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=CRAM-MD5 ACL ACL2=UNION
    2.786 OK CAPABILITY completed
    WROTE May 19 17:14:19.659 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    3.786 LIST "" ""
    READ May 19 17:14:19.718 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    * LIST (\Noselect) "." ""
    3.786 OK LIST completed
    WROTE May 19 17:14:19.755 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    4.786 APPEND "INBOX.Drafts (ClickMarkets-SA)" (\Seen \Draft $NotJunk NotJunk) "19-May-2009 17:07:30 -0700" {4525}
    READ May 19 17:14:19.818 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040
    + OK
    WROTE May 19 17:14:19.855 [kCFStreamSocketSecurityLevelNegotiatedSSL] -- host:mail.spamarrest.com -- port:993 -- socket:0x182eff40 -- thread:0x19fed040

    Okay I did a little more digging and found another thread that answers this issue.
    http://discussions.apple.com/thread.jspa?threadID=1276506

  • Help me pls! - Infinite loop!!

    Dear Guys,
    I am totally lost in my codes, pls help, TQ:
    import java.io.*;
    public class opReadLine {
         public opReadLine() {} //class constructor
         public static void main(String args[]) {
              FileReader inFile;
              BufferedReader inData;
              try {
                   inFile = new FileReader("test.cfg");
                   inData = new BufferedReader(inFile);
                   String temp = inData.readLine();
                   do {
                        System.out.println("The UID is: " + temp);
                   } while (temp != "END");
                   inData.close();
              catch (IOException ie) {
              ie.printStackTrace();
    Content of "test.cfg":
    END
    note: there is no blank line above "END"!!
    Rgds,
    Daniel

    Sorry I forgot to state the problem I am facing and the code I actually wanted.
    I want my code to read from a file line by line until it meets the word "END".
    However, I found there is a big syntax problem in:
    do {
    } while (temp != "END");
    The result for the code above is infinite loop of System.out.println("The UID is: " + temp);
    However,
    when I changed the code to:
    do {
    } while (temp == "END");
    it will execute "System.out.println(The UID is: " + temp) once and stops.
    In other words, the code recognizes END, but why when I try to compare with !=, it gives me problem??
    Pls help! TQ

  • MVC problem - infinite loop?

    I'm going to use a horribly oversimplified example to make my point here, because if I were to describe the actual code I'm looking at, it would take the better part of the afternoon and I'd probably bore you all to tears in the process. So, for the sake of argument, let's assume the following model object:
    public class MyModelObject
      private int a;
      private int b;
      private int c;
      public void setA(int newA)
        a = newA;
        b = newA + SOME_CONSTANT;
        c = newA + SOME_OTHER_CONSTANT;
      public void setB(int newB)
        this.setA(SOME_CONSTANT-newB);
      public void setC(int newC)
        this.setA(SOME_OTHER_CONSTANT-newC);
      public int getA()
        return a;
      public int getB()
        return b;
      public int getC()
        return c;
    }So what we see from this is that the setter for one class property actually changes the value of all three class properties (whether this is good design or not is questionable, but keep in mind this is a horribly simplified example for discussion purposes). The point is that the rules regarding the internal state of MyModelObject are governed entirely within that class - the controller and view don't know about these rules (again, questionable design, but bear with me here).
    Now let's imagine we have a view class that displays a MyModelObject instance and allows the user to change the value of a, b, or c. We also have a controller class that observes the view and responds to changes. When the user modifies the value of, let's say b, the controller will respond to that change by calling the setB() method in MyModelObject. Problem is, now the model and the view are out of synch... someone has to tell the view that the other two class properties have also been modified as a result of calling setB() - whose responsibility is this? Should the model inform the view that something has changed so that the view can redisplay it, or should the view observe the model and automatically redisplay whenever the model is modified?
    More importantly - let's say the controller is observing the view for changes, and the view is observing the model for changes... how do you avoid an infinite loop? For example, the user changes the value of b in the view, which causes the internal state of MyModelObject to be modified, which causes a change in the view, which causes a change in the model, and so on and so forth.
    A twist on the above problem is that it is illegal in some Swing components (JTextPane, for instance) to modify the view while a change notification is in progress... so something like this would throw an IllegalStateException:
    //somewhere in the controller
    public void insertUpdate(DocumentEvent docEvent)
      //update the model
      myModelObject.handleChange(docEvent);
      //now redisplay since the model has changed:
      myTextPane.display(myModelObject);
      // IllegalStateException is raised - Attempt to mutate in notification
    }This fails because you can't change the state of the view component in the event handler for a view change event. How do you get around this using proper MVC architecture? Or am I completely out to lunch here?

    The view shouldn't send events to the controller unless they make sense... For example, it shouldn't fire a change event when the user types in a new value. But only if the user presses enter, or the view loses focus (if this gesture is taken as equivalent).
    So when the change of the view comes from the side-effects of a setter of some property, it should fire no event (so that it will not loop). So it sounds no big problem (if such a distinction of events is easy - it should).

  • Infinite Loop issue in Encore CS5.1

    I have never been as angry at a piece of software as I am with Adobe Encore. I have been crashing it for almost a week now and I still am no closer to figureing out the problem...
    I have a 90 minute feature in Pr that I exported as an SD 16:9 (progressive frames) set of m2vs.  I also exported a single AC3 audio file using Surcode.  The moment I import any of the video the software becomes unstable.  My current methodology involves setting up the entire menu system (one SD main menu and 3 chapter sub menus), then import the AC3 as a timeline, then finally importing the M2Vs, one at a time saving after every successful import.  No dynamic links or anything unusual.
    Even though it is a 4GB SD feature the Encore process is using almost 2GB of memory when it seems to be working right.  Whenever I try to perform any task I get the (Not Responding) notice and I have to look at the process list.  If the CPU is fluctuating I have a good chance that control will return, if it locks in at 8% then it is stuck in some kind of infinite loop and will never come back.  At that point I kill off the program and try to see if the last saved session will load.  While in the infinite loop the memory will count up to about 3GB thae get knocked down to about 1GB, then start counting back up again.
    I have successfully completed the CD creation process once or twice, but it can take mnore than a day to complete what should take 20 minutes.
    I have deleted the Media Cache DB, moved the Media Cache DB, re-installed the software, and searched the net for a solution.  Nada...
    I am doing this work on my editor:
    OS Name Microsoft Windows 7 Ultimate
    Version 6.1.7601 Service Pack 1 Build 7601
    Other OS Description  Not Available
    OS Manufacturer Microsoft Corporation
    System Name EDITORPC
    System Manufacturer System manufacturer
    System Model System Product Name
    System Type x64-based PC
    Processor Intel(R) Core(TM) i7 CPU         980  @ 3.33GHz, 3750 Mhz, 6 Core(s), 12 Logical Processor(s)
    BIOS Version/Date American Megatrends Inc. 1001, 12/24/2010
    SMBIOS Version 2.5
    Windows Directory C:\Windows
    System Directory C:\Windows\system32
    Boot Device \Device\HarddiskVolume5
    Locale United States
    Hardware Abstraction Layer Version = "6.1.7601.17514"
    User Name EditorPC\bgruen
    Time Zone Eastern Daylight Time
    Installed Physical Memory (RAM) 24.0 GB
    Total Physical Memory 24.0 GB
    Available Physical Memory 20.1 GB
    Total Virtual Memory 48.0 GB
    Available Virtual Memory 44.0 GB
    Page File Space 24.0 GB
    Page File C:\pagefile.sys
    Any suggestions?
           Bob

    I'm don't think that is the "same problem," unless you are mixing one ac3 with multiple m2vs on the same timeline. (If the following doesn't solve your issue, start a new thread.)
    In any event, the following may not be directly applicable to your OS or situation, but includes global issues and specifics. Look in particular at numbers 1 and 4.
    Troubleshoot system errors and freezes | Adobe software on Mac OS 10.x
    http://kb2.adobe.com/cps/824/cpsid_82414.html
    Edit: Reading my mind? I'll add this to your new thread!

  • Start/Stop Buttons and infinite loop exit

    I am trying to make a GUI with a Start/Stop and an Exit button. Initially the button will have the label "Start". When i push it, its label should become "Stop" and an infinite loop function will begin. I want the loop to run until i press the Stop or Exit button.
    The problem is that when the loop starts i can't press neither of the buttons. The "Start" button changes its label into "Stop" only if i make the loop finite and it ends.
    Here is the source:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class StartStopButtons extends JFrame{
        Component visualComponent = null;
        JPanel panel = null;
        JLabel statusBar = null;
         public StartStopButtons() {
              setSize(160, 70);
              getContentPane().setLayout(new BorderLayout());
            panel = new JPanel();
            panel.setLayout(new BorderLayout());
            getContentPane().add(panel, BorderLayout.CENTER);
            final JPanel panel_1 = new JPanel();
            panel.add(panel_1, BorderLayout.CENTER);
            final JButton startButton = new JButton();
            startButton.addActionListener(new ActionListener() {
                 public void actionPerformed(final ActionEvent e) {
                    String action = e.getActionCommand();
                    if (action.equals("Start")) {
                         System.out.println("Start Loop");
                         startButton.setText("Stop");
                         myLoop ();
                    if (action.equals("Stop")) {
                         System.out.println("Stop Loop");
                         System.exit(0);
            startButton.setText("Start");
            panel_1.add(startButton);
            final JButton exitButton = new JButton();
            exitButton.addActionListener(new ActionListener() {
                 public void actionPerformed(final ActionEvent e) {
                    String action = e.getActionCommand();
                    if (action.equals("Exit")) {
                        System.exit(0);
            panel_1.add(exitButton);
            exitButton.setText("Exit");
         public void myLoop() {
              for (int i = 0; ; i++)
                   System.out.println(i);
         public static void main(String[] args) {
              StartStopButtons ssB = new StartStopButtons();
              ssB.setVisible(true);
    }

    I works just fine. Here is the source and thanks for the help.
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    public class StartStopButtons extends JFrame implements ActionListener, Runnable{
        Component visualComponent = null;
        JPanel panel = null;
        JLabel statusBar = null;
        Thread thread;
        JButton startButton;
         public StartStopButtons() {
            try {
                UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
            } catch(Exception e) {}
              setSize(160, 70);
              getContentPane().setLayout(new BorderLayout());
            panel = new JPanel();
            panel.setLayout(new BorderLayout());
            getContentPane().add(panel, BorderLayout.CENTER);
            final JPanel panel_1 = new JPanel();
            panel.add(panel_1, BorderLayout.CENTER);
            startButton = new JButton();
            startButton.addActionListener(this);
            startButton.setText("Start");
            panel_1.add(startButton);
            final JButton exitButton = new JButton();
            exitButton.addActionListener(new ActionListener() {
                 public void actionPerformed(final ActionEvent e) {
                    String action = e.getActionCommand();
                    if (action.equals("Exit")) {
                        System.exit(0);
            panel_1.add(exitButton);
            exitButton.setText("Exit");
         public void actionPerformed(ActionEvent e) {
              String action = e.getActionCommand();
              if (action.equals("Start")) {
                   startButton.setText("Stop");
                   thread = new Thread( this );
                   thread.start();
              if (action.equals("Stop")) {
                System.exit(0);
         public void run() {
              myLoop();
         public void myLoop() {
              for (int i = 0; ; i++)
                   System.out.println(i);
         public static void main(String[] args) {
              StartStopButtons ssB = new StartStopButtons();
              ssB.setVisible(true);
    }

  • JButton, flashcards and an infinite loop

    I'm trying a create a flashcard panel for Japanese kana. I have a class JCWidget that consists of the image of the specific symbol and its name.
    I could think of only two ways to create autoadvancing flashcards. Using Thread or Timer. May be there are more, and I would welcome the ideas.
    When the start button is pushed, an image and a name should change in a set ammount of seconds and so on, until the stop button is pressed But there is a problem - output is shown only after actionPerformed method is executed completely, resulting in infinite loop.
    Code using threads:
    public static JPanel addPanel2()
        jP2 = new JPanel(new GridLayout(2, 1));
        jcw = new JCWidget(arr, isKatakana);
        final JLabel letter = jcw.getLetter();
        final JLabel text = new JLabel(jcw.getLetterName());
        final JButton start = new JButton("Start flashcards");
        final JButton stop = new JButton("Stop flashcards");
        text.setHorizontalAlignment(JLabel.CENTER);
        stop.setEnabled(false);
        jP2.add(letter);
        jP2.add(start);
        jP2.add(text);
        jP2.add(stop);
        start.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            start.setEnabled(false);
            stop.setEnabled(true);
           while(stop.isEnabled())
              try {jcw.sleep(500);}
              catch (InterruptedException exept) {jcw.interrupt();}
              jcw = new JCWidget(arr, isKatakana);
              letter.setIcon(jcw.getLetter().getIcon());
              text.setText(jcw.getLetterName());
        stop.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            stop.setEnabled(false);
            start.setEnabled(true);
            jcw.notify();
        return jP2;
      }Code using timer:
    public static JPanel addPanel2()
        jP2 = new JPanel(new GridLayout(2, 1));
        jcw = new JCWidget(arr, isKatakana);
        final JLabel letter = jcw.getLetter();
        final JLabel text = new JLabel(jcw.getLetterName());
        final JButton start = new JButton("Start flashcards");
        final JButton stop = new JButton("Stop flashcards");
        text.setHorizontalAlignment(JLabel.CENTER);
        stop.setEnabled(false);
        jP2.add(letter);
        jP2.add(start);
        jP2.add(text);
        jP2.add(stop);
        final Timer timer = new Timer(1000, new ActionListener()
          public void actionPerformed(ActionEvent e)
           // while(stop.isEnabled())
              letter.setIcon(jcw.getLetter().getIcon());
              text.setText(jcw.getLetterName());
        start.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            start.setEnabled(false);
            stop.setEnabled(true);
            timer.start();
        stop.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            stop.setEnabled(false);
            start.setEnabled(true);
            timer.stop();
        return jP2;
      }When running for a single iteration, everything works perfectly, (although with timer can work only once - after pushing start button for the second time nothing would happen, with threads there is no problem in that.
    I tried to use for loop with limited number of iterations, but the output is changed only once - at the end of the loop. And with the while loop, program completely freezes up.
    Could someone, please, help?

        final Timer timer = new Timer(1000, 1000, new MyTimerActionListener());
        start.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            start.setEnabled(false);
            stop.setEnabled(true);
            timer.start();
        });To do the timer code better, you might want to construct a new timer each time the start button is pushed. Something like so:
        start.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            Timer timer = new Timer(1000, new MyTimerActionListener());
            start.setEnabled(false);
            stop.setEnabled(true);
            timer.start();
        });

  • Program enters infinite loop.

    this is the first program i'm writing with sockets and is also a step towards making a chat application. my problem is that the program enters infinite loop.
    package server;
    import java.net.*;
    import java.io.*;
    class Server
        public static void main(String[] args) throws Exception
            ServerSocket ss = new ServerSocket(9090);
            Socket soc = ss.accept();
            BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
            String str = in.readLine();
            while(str!="")
                System.out.println(str);
                str = in.readLine();
            soc.close();
            ss.close();
    }this was the server - a seperate application. below is a part of the client - a seperate application
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            try
                InetAddress ip = InetAddress.getByName("127.0.0.1");
                Socket soc = new Socket(ip,9090);
                PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(soc.getOutputStream())),true);
                str_out = jTextArea2.getText();
                while(str_out!="")
                    out.println(str_out);
                    str_out = jTextArea2.getText();
                soc.close();
            catch(Exception e)
                System.out.println("Error sending message");
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            str_out = "";
            jTextArea2.setText(str_out);
        }  when i press button send (jButton1) the text from the text area jTextArea2 is supposed to go to the server and then the server should display it in its out put screen. i tried sending hello and the server went on printing hello continously.
    pleas help.

    String str = in.readLine();
    while(str!="")
    System.out.println(str);
    str = in.readLine();
    }You need to test for (str != null) above too, or instead of str != "".

  • Why does javadoc goes into an infinite loop

    at my dos prompt , in the same directory as my Page.java file, i type javadoc Page.java
    why does it go into an infinite loop? instead of producing any documentation
    it just says for example
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    javadoc Page.java
    Stephen

    this is a sample page -- i'm using jdk 1.4 trying to run javadoc Tracer.class or javadoc Tracer.java or javadoc Tracer gives throws the console into an infinite loop with the statement being printed over and over again. But i haven't just noticed this problem with javadoc -- i noticed this problem with certain types of mistakes in the code rather than just displaying the compiler error -- it creates this infinite loop in the dos console window. any thoughts ?
    here is my version.
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    * Tracer.class logs items according to the following criteria:
    * 2 = goes to text file Crawler_log.txt
    * 1 = goes to console window because it is higher priority.
    * @author Stephen
    * @version 1.0
    * @since June 2002
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    class Tracer{
         public static void log(int traceLevel, String message, Object value)
              pout.write(getLogFileDate(new Date()) +" >" + message + " value = " + value.toString());
         public static void log(int traceLevel, String message )
              pout.write("HI HOW ARE YOU " ) ;
              pout.flush();
         //public static accessor method
         public static Tracer getTracerInstance()
              return tracerInstance;
         private static String getLogFileDate(Date d )
              String s = df.format(d);
              String s1= s.replace(',','-');
              String s2= s1.replace(' ','-');
              String s3= s2.replace(':','.');
              System.out.println("getLogFileDate() = " + s3 ) ;
              return s3;
         //private instance
         private Tracer(){
              System.out.println("Tracer constructor works");
              df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
              date                    = new java.util.Date();
              try{
              pout = new PrintWriter(new BufferedWriter(new FileWriter("Crawler_log"+getLogFileDate(new Date())+".txt", true)));
              pout.write("**************** New Log File Created "+ getLogFileDate(new Date()) +"****************");
              pout.flush();
              }catch (IOException e){
              System.out.println("**********THERE WAS A CRITICAL ERROR GETTING TRACER SINGLETON INITIALIZED. APPLICATION WILL STOP EXECUTION. ******* ");
         public static void main(String[] argz){
         System.out.println("main method starts ");
         Tracer tt = Tracer.getTracerInstance();
         System.out.println("main method successfully gets Tracer instance tt. "+ tt.toString());
         //the next method is where it fails - on pout.write() of log method. Why ?
         tt.log(1, "HIGH PRIORITY");
         System.out.println("main method ends ");
         //private static reference
         private static Tracer tracerInstance = new Tracer();
         private static Date date     = null;
         private static PrintWriter pout = null;
         public static DateFormat df = null;
    }

  • SQL stored procedure Staging.GroomDwStagingData stuck in infinite loop, consuming excessive CPU

    Hello
    I'm hoping that someone here might be able to help or point me in the right direction. Apologies for the long post.
    Just to set the scene, I am a SQL Server DBA and have very limited experience with System Centre so please go easy on me.
    At the company I am currently working they are complaining about very poor performance when running reports (any).
    Quick look at the database server and CPU utilisation being a constant 90-95%, meant that you dont have to be Sherlock Holmes to realise there is a problem. The instance consuming the majority of the CPU is the instance hosting the datawarehouse and in particular
    a stored procedure in the DWStagingAndConfig database called Staging.GroomDwStagingData.
    This stored procedure executes continually for 2 hours performing 500,000,000 reads per execution before "timing out". It is then executed again for another 2 hours etc etc.
    After a bit of diagnosis it seems that the issue is either a bug or that there is something wrong with our data in that a stored procedure is stuck in an infinite loop
    System Center 2012 SP1 CU2 (5.0.7804.1300)
    Diagnosis details
    SQL connection details
    program name = SC DAL--GroomingWriteModule
    set quoted_identifier on
    set arithabort off
    set numeric_roundabort off
    set ansi_warnings on
    set ansi_padding on
    set ansi_nulls on
    set concat_null_yields_null on
    set cursor_close_on_commit off
    set implicit_transactions off
    set language us_english
    set dateformat mdy
    set datefirst 7
    set transaction isolation level read committed
    Store procedures executed
    1. dbo.p_GetDwStagingGroomingConfig (executes immediately)
    2. Staging.GroomDwStagingData (this is the procedure that executes in 2 hours before being cancelled)
    The 1st stored procedure seems to return a table with the "xml" / required parameters to execute Staging.GroomDwStagingData
    Sample xml below (cut right down)
    <Config>
    <Target>
    <ModuleName>TransformActivityDim</ModuleName>
    <WarehouseEntityName>ActivityDim</WarehouseEntityName>
    <RequiredWarehouseEntityName>MTV_System$WorkItem$Activity</RequiredWarehouseEntityName>
    <Watermark>2015-01-30T08:59:14.397</Watermark>
    </Target>
    <Target>
    <ModuleName>TransformActivityDim</ModuleName>
    <WarehouseEntityName>ActivityDim</WarehouseEntityName>
    <RequiredWarehouseEntityName>MTV_System$WorkItem$Activity</RequiredWarehouseEntityName>
    <ManagedTypeViewName>MTV_Microsoft$SystemCenter$Orchestrator$RunbookAutomationActivity</ManagedTypeViewName>
    <Watermark>2015-01-30T08:59:14.397</Watermark>
    </Target>
    </Config>
    If you look carefully you will see that the 1st <target> is missing the ManagedTypeViewName, which when "shredded" by the Staging.GroomDwStagingData returns the following result set
    Example
    DECLARE @Config xml
    DECLARE @GroomingCriteria NVARCHAR(MAX)
    SET @GroomingCriteria = '<Config><Target><ModuleName>TransformActivityDim</ModuleName><WarehouseEntityName>ActivityDim</WarehouseEntityName><RequiredWarehouseEntityName>MTV_System$WorkItem$Activity</RequiredWarehouseEntityName><Watermark>2015-01-30T08:59:14.397</Watermark></Target><Target><ModuleName>TransformActivityDim</ModuleName><WarehouseEntityName>ActivityDim</WarehouseEntityName><RequiredWarehouseEntityName>MTV_System$WorkItem$Activity</RequiredWarehouseEntityName><ManagedTypeViewName>MTV_Microsoft$SystemCenter$Orchestrator$RunbookAutomationActivity</ManagedTypeViewName><Watermark>2015-01-30T08:59:14.397</Watermark></Target></Config>'
    SET @Config = CONVERT(xml, @GroomingCriteria)
    SELECT
    ModuleName = p.value(N'child::ModuleName[1]', N'nvarchar(255)')
    ,WarehouseEntityName = p.value(N'child::WarehouseEntityName[1]', N'nvarchar(255)')
    ,RequiredWarehouseEntityName =p.value(N'child::RequiredWarehouseEntityName[1]', N'nvarchar(255)')
    ,ManagedTypeViewName = p.value(N'child::ManagedTypeViewName[1]', N'nvarchar(255)')
    ,Watermark = p.value(N'child::Watermark[1]', N'datetime')
    FROM @Config.nodes(N'/Config/*') Elem(p)
    /* RESULTS - NOTE THE NULL VALUE FOR ManagedTypeViewName
    ModuleName WarehouseEntityName RequiredWarehouseEntityName ManagedTypeViewName Watermark
    TransformActivityDim ActivityDim MTV_System$WorkItem$Activity NULL 2015-01-30 08:59:14.397
    TransformActivityDim ActivityDim MTV_System$WorkItem$Activity MTV_Microsoft$SystemCenter$Orchestrator$RunbookAutomationActivity 2015-01-30 08:59:14.397
    When the procedure enters the loop to build its dynamic SQL to delete relevant rows from the inbound schema tables it concatenates various options / variables into an executable string. However when adding a NULL value to a string the entire string becomes
    NULL which then gets executed.
    Whilst executing "EXEC(NULL)" would cause SQL to throw an error and be caught, executing the following doesnt
    DECLARE @null_string VARCHAR(100)
    SET @null_string = 'hello world ' + NULL
    EXEC(@null_string)
    SELECT @null_string
    So as it hasnt caused an error the next part of the procedure is to move to the next record and this is why its caught in an infinite loop
    DELETE @items WHERE ManagedTypeViewName = @View
    The value for the variable @View is the ManagedTypeViewName which is NULL, as ANSI_NULLS are set to ON in the connection and not overridded in the procedure then the above statement wont delete anything as it needs to handle NULL values differently (IS NULL),
    so we are now stuck in an infinite loop executing NULL for 2 hours until cancelled.
    I amended the stored procedure and added the following line before the loop statement which had the desired effect and "fixed" the performance issue for the time being
    DELETE @items WHERE ManagedTypeViewName IS NULL
    I also noticed that the following line in dbo.p_GetDwStagingGroomingConfig is commented out (no idea why as no notes in the procedure)
    --AND COALESCE(i.ManagedTypeViewName, j.RelationshipTypeViewName) IS NOT NULL
    There are obviously other ways to mitigate the dynamic SQL string being NULL, there's more than one way to skin a cat and thats not why I am asking this question, but what I am concerned about is that is there a reason that the xml / @GroomingCriteria is incomplete
    and / or that the procedures dont handle potential NULL values.
    I cant find any documentation, KBs, forum posts of anyone else having this issue which somewhat surprises me.
    Would be grateful of any help / advice that anyone can provide or if someone can look at their 2 stored procedures on a later version to see if it has already been fixed. Or is it simply that we have orphaned data, this is the bit that concerns most as I dont
    really want to be deleting / updating data when I have no idea what the knock on effect might be
    Many many thanks
    Andy

    First thing I would do is upgrade to 2012 R2 UR5. If you are running non-US dates you need the UR5 hotfix also.
    Rob Ford scsmnz.net
    Cireson www.cireson.com
    For a free SCSM 2012 Notify Analyst app click
    here

  • Update routine infinite loop

    Hello Experts,
    For loading ODS2 we are making a lookup on ODS1 for 0material based on
    purchaing document number, item line item.
    Is there any mistake in the start routine or update routine.
    Because the load goes in infinite loop. I think update routine should be changed.
    Any suggestions are appreciated
    Start routine:
    data: begin of itab occurs 0,
            pur_doc like /BIC/AZODS100-OI_EBELN,
            item like /BIC/AZODS100-OI_EBELP,
            material like /BIC/AZODS100-material,
          end of itab.
    clear itab.
    select OI_EBELN OI_EBELP MAT_PLANT from /BIC/AZODS100
             into table itab.
    Update routine for 0material
    loop at itab where pur_doc = COMM_STRUCTURE-OI_EBELN
                       and item = COMM_STRUCTURE-OI_EBELP.
           RESULT = itab-matplant.
    endloop.

    Hi,
    this takes a long time, because with each record of your data packaged it is doing the loop and scanning each row of the internal table. Use the following instead.
    Start routine:
    types: begin of t_itab,
    pur_doc like /BIC/AZODS100-OI_EBELN,
    item like /BIC/AZODS100-OI_EBELP,
    material like /BIC/AZODS100-material,
    end of t_itab.
    data: itab type hashed table of t_itab with unique key pur_doc item.
    select OI_EBELN OI_EBELP MAT_PLANT from /BIC/AZODS100
    into table itab order by oi_ebeln oi_ebelp mat_plant.
    I hope these fields are the key of the ods object.
    Update routine for 0material
    data: wa_itab type t_itab.
    read table itab into wa_itab with table key pur_doc = COMM_STRUCTURE-OI_EBELN
    item = COMM_STRUCTURE-OI_EBELP.
    if sy-subrc = 0.
    RESULT = wa_itab-matplant.
    else.
    clear result.
    endif.
    Hope this helps
    regards
    Siggi

  • Infinite loop problem

    Hi there,
    This is the second time I have posted this problem, as the last solution I was offered did not seem to work. Here is the problem:
    I have written a method to search through a text file for a word and replace it with another word. That word can either be on its own in the document or as part of another word. So, if the search word was "foot" and the replace word was "dog", the word "football" in the document would become "dogball".
    This method works fine, except for when the replace word is the same as the search word. Basically, if someone searched for "dog" and wanted to replace it with "dog dog" or even just "dog", the program goes into an infinite loop. I understand why it is doing this, but I don't know how to prevent it from happening.
    Now, to make it worse I have to stick to this array style structure and method of solving the problem. I know there is a way to do this by building temporary strings and then concatenating them at the end and returning them to their previous position in the array. The reason I know this is because a friend of mine has managed it. She also happens to be a girl.
    So, I am asking you all to assist in defending men's intelligence by helping me see where I am going wrong in this method. Please.
    Here is the method:
    // Search the document for a string and replace it with another string        
         public String [] SearchReplace() {
              // Declare variables to be used in the method
              String SecondSubstring;
              String FirstSubstring;
              int ReplaceNumber = 0;
              // Loop through the lines of text stored as strings contained in the array
              for (int i = 0; i < NumberOfLines; i++) {
                        // As long as the string contains an instance of the search string, run the method                    
                        while (StrArray.indexOf(SearchW) >= 0) {
                             // Make a string of all the characters after the search word
                             SecondSubstring = StrArray[i].substring(StrArray[i].indexOf(SearchW) + SearchW.length());
                             // Make a string of all the characters before the search word
                             FirstSubstring = StrArray[i].substring(0, StrArray[i].indexOf(SearchW));
                             // Concatenate FirstSubstring with the replace word to make a new string
                             String FirstHalf = FirstSubstring.concat(ReplaceW);
                             // Concatenate the new string with SecondSubstring to make the whole replaced string
                             String FullString = FirstHalf.concat(SecondSubstring);
                             // Put this altered string back to its original place in the array
                             StrArray[i] = FullString;
                             // Increment ReplaceNumber to count the replacements made
                             ReplaceNumber++;
              // Print the numbers of replacements made
              System.out.println("\nA total of " + ReplaceNumber + " changes made.\n");
              // Display the searched and replaced contents of the file
              return StrArray;
    Any suggestions, pointers or solutions would be much appreciated.
    Thanks very much.

    Doing it the "old fashioned" way:
    You need to keep track of a "from index" so you don't search through parts of the string you've already replaced:
           public static void main(String args[]) {          
              try {     
                   String[] lines = new String[] {
                        "the dog went up the dog hill",
                        "all dogs go to dog heaven",
                        "the dogball takes place on 3rd april"
                   lines = replace(lines, "dog", "dog dog");
                   for (int i = 0; i < lines.length; i++) {
                        System.out.println(lines);
              } catch (Exception e) {
                   e.printStackTrace();
         private static String[] replace(String[] lines, String searchWord, String replaceWord) {
              if (searchWord.equals(replaceWord)) return lines; // nothing to do          
              for (int i = 0; i < lines.length; i++) {
                   int fromIndex = 0; // from index to do indexOf
                   String line = lines[i];
                   while (line.indexOf(searchWord, fromIndex) != -1) {
                        final int index = line.indexOf(searchWord, fromIndex);
                        line = line.substring(0, index) + replaceWord + line.substring(index + searchWord.length());
                        fromIndex = (line.substring(0, index) + replaceWord).length();
                   lines[i] = line; // replace
              return lines;

Maybe you are looking for