Printing a stack

ok i've been working on a program for a couple of weeks and all I have left to do is print the stack. I'm pushing Grids as 2D arrays onto the stack and that part is working correctly (used the peek method) but when I try to print the entire stack it prints the last Grid the length of the stack. My code is:
while(!solution.empty())
temp= (char [][])solution.pop();
System.out.println();
for(int r=0; r<7; r++)
System.out.println();
for(int c=0; c<7; c++)
System.out.print(temp[r][c]+" ");
Can anyone see a problem with this to make it just print the same grid?

Or looked at differently
when you take your char[][] foo and push it onto the stack then you modify foo, you are simultaneously modifying the one that is out on the stack because all the stack has on it, is a pointer back to the foo object.
Eventually you have a dozen pointers in the stack to foo. They all point to exactly the same single one copy that you ever had. So no surprise, when you change one you change them all. They are all the same.
If you want a copy, you must create a new char[][] object, and use a couple nested for loops to copy each char out of the original into the new object. Now you can push the copy and modify the original without screwing up the one on the stack.
BTW if you ever hear anyone use the phrase "pointer semantics" as in "objects in Java (and every other OOL) have pointer semantics" what they mean is that unless you are careful it is very easy to make exactly the mistake that you just made.
I would estimate that there are exactly zero good programmers that did not learn about this paritcular blunder by making this same mistake and then wondering for hours if they hadn't uncovered some bug in the library or the compiler because, "There is NOTHING wrong with my code!"
Enjoy!

Similar Messages

  • Want to print the stack trace from the code

    looking for a way to print the stack trace from the CVI code.
    Thanks!

    First I would share the movie. If I was making a DVD, I would use SHARE/To Media Browser in LARGE size.
    Then I would use a free application called MPEG Streamclip,
    Get MPEG Streamclip, which is free. (google MPEG Streamclip from Squared 5)
    Open MPEG Streamclip.
    In the Finder, go to Movies/iMovie Projects, and right click on your project. Then, right-click/Show Package Contents. Navigate to the Movies folder in the package and find the LARGE movie. (Note: you are in the bowels of the Media Browser)
    Drag this movie into MPEG Streamclip. (It will not actually move anywhere. This tells MPEG Streamclip how to find it.)
    In MPEG Streamclip, move the playhead to the frame you want.
    In MPEG Streamclip, click FILE/EXPORT FRAME.
    Choose JPEG, TIFF, or PNG and give it a name.
    You can then drag this photo into iPhoto, iDVD, or wherever you need it.
    (Assuming you already know this) In iDVD, you can find the Media Browser at the lower right of the Window. Navigate to your project and drag it into iDVD.

  • Make java run without printing the stack trace

    I have a GUI program which appears to work for all test cases. Basically what it does is prints out data from a linked list allowing the user to traverse the list with Next and Previous buttons which call a list iterator next/previous method call, and then display the current item in the list. The original problem arose when dealing with alternating calls to next and previous, which since list iterator does not have a current pointer, returned the same element ad infinitum. I modified the method to check for alternating button presses, and it seems to work, except for cases where there are two elements in the list. In this case it still works, printing the correct element, but it also prints to the command line an Exception in Thread AWT...NoSuchElementException. My question is, is there any way to tell the program to not print out this stack trace and just keep running quietly through the Exception?

    I'm not an expert at error handling, but wouldn't it work to put the code that throws the exception in a try/catch block?
    like
    try {
        //code that causes exception
    } catch (NoSuchElementException e) {
        //do nothing
    }Might not work, but it's worth a try...

  • SEVERE: SAAJ0009:  How do I stop stack trace being printed to standard out

    Anyone know why the following stack trace is printed when connection.call(message, endpoint); throws an exception? It happens when the server or web service is offline
    using jdb I can see that the next statement to execute is the return("FAIL .... but the stack trace is already printed by then. How do I tell it not to print the stack trace. I've tried adding a catch for java.io.IOException but the compiler says it's not thrown. Any ideas
    SOAPMessage response = null;
    try{
    response = connection.call(message, endpoint); <= blows up here "myClient.auth myClient.java:333)
    connection.close();
    catch (SOAPException ex){
    return("FAIL Error sending authentication soap message " + ex.getMessage());
    java.io.IOException
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:593)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:272)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:29)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPCon
    ection.java:151)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:12)
    at myClient.auth(myClient.java:333)
    at myClient.send(myClient.java:93)
    at myClient.main(myClient.java:550)
    Caused by: java.net.ProtocolException: Server redirected too many times (20)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:800)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:272)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:27)
    ... 6 more
    May 18, 2004 12:23:05 PM com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection post
    SEVERE: SAAJ0009: Message send failed
    java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send
    failed
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:12)
    at myClient.authenticate(myClient.java:333)
    at myClient.send(myClient.java:93)
    at myClient.main(myClient.java:550)
    Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:30)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConection.java:151)
    ... 5 more
    Caused by: java.io.IOException
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:593)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:272)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:29)
    ... 6 more
    Caused by: java.net.ProtocolException: Server redirected too many times (20)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:800)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:272)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:27)
    ... 6 more

    For anyone who's interested, apparently I'm not the only one with this problem, others have asked the developrs to remove printStackTrace() from the SAAJ code. For now we have to redirect standard error or ignore

  • Printing to windows printer via SMB - Printing garbled text

    Hi all.
    I have been working on this issue for around 3 hrs this morning and finally figured it out. Thought I'd post what I did to help others with similar issues.
    Here's my set up:
    I have a PC with HP photosmart printer connected to it. I've a Macbook Pro that I connect to the PC via SMB protocol for file sharing. If I wanted to print from the mac to the printer I had to disconnect the printer form the PC and directly connect it to the mac. I wanted to be able to print from the Mac to the printer via the PC. Should be that hard right as I have already successfully file shared via SMB.
    Well it was a little difficult. I did many a search on here and the web and eventually found the following article:
    http://docs.info.apple.com/article.html?path=Mac/10.4/en/mh2231.html
    So, following these steps i tried to print a single page word (office 2008 for mac) doc from the mac. Hey presto! The printer kicked into life and started...
    ...problem was it spewed out around 20 pages of Garbled text! I tought it might have been print jobs stacked up from the last unsuccessful attemt at doing this but no, no jobs there. Thought it might have been Word/office for mac, etc. so tried to print from Text Edit but same thing.
    After hrs of screaming, F'ing & Blinding I finally figured out it was to do with what printer I had it set up on. I went into Print & Fax in System Preferences, highlighted the printer and clicked printer setup tab. In the drop down tab I selected printer model. It was set on Generic.
    In the drop down list there it shows a huge selection of printers. my particular model was not there so I chose the closest thing and selected that.
    After exiting all that and trying again it worked.
    I'm very happy.
    Adam

    Hi iVirtual, what Mac OS are you running, Leopard (10.5.4) or Tiger (10.4.11)? Also, is your printer directly attached to your pc or is it a network printer directly on the local area network? One last question, do you have a firewall (like Trend Micro or Norton Internet Security) on your PC?
    From my Mac running Leopard, I have no problem printing to a printer directly attached to my WindowsXP machine. However, I don't have the same luck from my Tiger Machines.
    When I print to any networked printer (by that I mean printers directly attached to the network) from the WindowsXP machine with SP3, I always have to use the IP address. The printer.local name no longer works since I installed SP3.
    simonparker, If your printer is directly attached to your PC using a USB cable, I don't think you'll be able to see it with the Bonjour Printer Wizard application. Since your printer is shared, you might check your WORKGROUP name on your PC. Something you might check is this:
    Do you have a password on your user account on the PC? You'll probably need a password on your PC account. I don't think you can share anything if you don't have a password (I could be wrong, but it has never worked for me without a password).
    On leopard, when I added the printer to the Mac I did this:
    1) bring up System Preferences/Print&Fax
    2) Press the + sign under the printer list, when the add window pops up, choose the "Windows" icon and you should see your workgroup name in the left list.
    3) Choose the workgroup and it should populate with your machine name.
    4) Select the machine name in the middle list and you should get a login and password dialog box.
    5) Enter your PC's Username and Password.
    6) You should see a list of shared printers in the right most list.
    7) Select the printer and then select the driver.
    Your printer should now be configured on the Mac. I know that I had to enter my PC's user name and password several times before I could print.

  • Printing double-sided copies

    I use a 2012 Macbook and use the USB cord to print to my HP P1102w.  I updated my macbook to the new OSX 10.9 (Maverick), and I see in previous discussions that there is no longer a pop-up window prompting the user to reinsert the paper into the tray for manual two-sided printing.  I opened the toner cover and closed it again, according to the directions given in the forum, and it does work.  However, when 20 of the 40 pages printed, the stack had page 40 on top and then even numbers all the way down.  My question is, how do I insert those pages back into the tray so that the correct numbers appear on the back of the appropriate pages?  In other words, how do I load the printed pages so that page 2 is on the back of page 1, page 4 on 3, etc.?

    Hi @Scooch,
    I see by your post that you would like to know how to flip the pages, when printing two-sided. I would like to help you out
    today.
    Take the printed stack from the output bin and then insert the stack printed side down into the tray
    with the top edge feeding into the product first.
    Have a nice day!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Javax.print problem/question

    Hello there! I'm trying to implement a printService. My service implements PrintJobListener, because my UC requires that the user be notified about print errors (printer off, out-of-papper etc.).
    Problem is, the only method being called on PrintJobListener is printJobNoMoreEvents(PrintJobEvent pje) no matter if it succeeded or not.
    Here's my clasess implementations:
    PrintService (implements runnable ...)
    public void run() {
              try {
                   DocFlavor format = DocFlavor.BYTE_ARRAY.AUTOSENSE;
                   Doc doc = new SimpleDoc(data,format,null);
                   PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                   aset.add(new Copies(1));
                   aset.add(MediaSizeName.ISO_A4);
                   aset.add(Sides.ONE_SIDED);
                   aset.add(PrintQuality.DRAFT);
                   // obt�m servi�o de impress�o default
                   PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                   DocPrintJob job = service.createPrintJob();
                   PrintJobWatcher pjDone = new PrintJobWatcher(job,this);
                   job.print(doc, null);
                   pjDone.waitForDone();
                   } catch (PrintException e) {
                        //TODO alterar o status do pedido
                        e.printStackTrace();
    public class PrintJobWatcher {
          boolean done = false;
          private DrogatelPrintService printService;  
                 PrintJobWatcher(DocPrintJob job, DrogatelPrintService service) {
                     job.addPrintJobListener(new PedidoJobListener());
                     this.printService = service;
                 public synchronized void waitForDone() {
                     try {
                         while (!done) {
                             wait();
                     } catch (InterruptedException e) {
                 private class PedidoJobListener implements PrintJobListener {
                      public void printDataTransferCompleted(PrintJobEvent pje) {
                           allDone();
                      public void printJobCanceled(PrintJobEvent pje) {
                           printService.atualizarStatusPedido(FasePedidoEnum.ERRO_IMPRESSAO);
                           allDone();
                      public void printJobCompleted(PrintJobEvent pje) {
                           printService.atualizarStatusPedido(FasePedidoEnum.IMPRESSO);
                           allDone();
                      public void printJobFailed(PrintJobEvent pje) {
                           printService.atualizarStatusPedido(FasePedidoEnum.ERRO_IMPRESSAO);
                           allDone();
                      public void printJobNoMoreEvents(PrintJobEvent pje) {
                           allDone();
                      public void printJobRequiresAttention(PrintJobEvent pje) {
                           printService.atualizarStatusPedido(FasePedidoEnum.ERRO_IMPRESSAO);
                           allDone();
                      void allDone() {
                        synchronized (PrintJobWatcher.this) {
                            done = true;
                            PrintJobWatcher.this.notify();
    My printer is an epson U220B partial cut. Configured on windows 2000.
    Please if anyone has any ideas on this subject please give me a hand here, I'm kinda in a trouble here ;)
    Thanks all

    First, print the stack traces in your catch blocks: without that, how can you know that you have a problem?
    Second, try use AUTOSENSE instead of TEXT_PLAIN_US_ASCII.

  • Stack overflow at line: 0

    Hi,
    I have one applet in a jsp page. When the page is loaded, I get a dialog box saying "Stack overflow at line: 0". It does not come all the time. When it comes, it comes just after the applet is loaded.
    I am using IE6. The problem is coming both in JRE1.4 and JRE1.5. I am not sure whether it is an applet problem or a javascript problem.
    After seraching a lot I find a similar post at:
    http://forum.java.sun.com/thread.jspa?threadID=519432&messageID=2500131#2500131
    But it does not give the solution.
    Any kind of help will be greatly appreciated. It is very urgent.

    Thanks for the reply.
    But in tnat case that should print the stack trace at
    the Java Console. Here what I get is, a small
    Javascript alert saying "Stack oveflow at line: 0".
    Nothing at Java Console, nothing at server console.
    And when I click OK button, everything goes fine.Then it's a javascript problem, and not a java problem. You should ask the question in a javascript forum.
    Kaj

  • Java Exception Stack Trace

    Whenever an exception object is created, its constructor is called. This constructor, calls super class constructor to fill in the exception stack trace and then the constructor uses printStackTrace() method to print the stack trace.
    This should print the stack trace automatically on the std out.
    However, in our exception handling code, unless we specifically use printStackTrace() it does not print stack trace.
    What is the reason for this?

    Hi,
    I am aware that not all Exceptions print stack trace to std out.
    I am specifically refering to SQLException. The constructor source code is
    public SQLException(String reason) {
         super(reason);
         this.SQLState = null;
         this.vendorCode = 0;
         if (!(this instanceof SQLWarning)) {
         if (DriverManager.getLogWriter() != null) {
              printStackTrace(DriverManager.getLogWriter());
    }

  • Is it possible to get the stack trace of procedure invocations in pld file?

    For example, if I have a package AAA in a pld file which has three procedure proc1, proc2, and proc3 defined. proc 3 will be invoked somewhere in proc2. proc2 will be invoked somewhere in proc1.
    Is it possible to print such stack trace in proc1? It will be very helpful if it is possible.

    See this post if you can figure out something out of it ....
    http://forum.java.sun.com/thread.jsp?forum=31&thread=391451

  • Selecting Photo's for Photo Lab printing

    I have a number of photo's that my family would like to take to the photo lab for professional printing.
    I'm just wondering if anyone has any suggestions of the best way this could be done in iPhoto (order prints is not supported in Australia).
    I was thinking the best way is to have the family browse the album, when they came across a photo they liked they could rate it, then create a smart folder to find all the photos with that specific rating. Then, I could export the selection to DVD. Anyone got any better tips?

    Eddie,
    If you don't already have a photo lab that you regularly use - you might want to take a handful of sample photos to several labs and then compare the results. That way you can entrust your family photos to the BEST lab.
    Some labs produce better prints than others. Some do their own 'post processing' (even if you tell them not to) that can affect the outcome of your prints. It's better to spend a few $$ geting samples printed at several labs, then to print your stack of family photos and get unsatisfactory results!
    If you are talking about burning to a DVD and not a CD, then I'm assuming you have a HUGE amount of prints to make!
    Steve

  • How i can print the Stacktrace

    hii..
    i want to print the stacktrace for my program below..
    package Langpack;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class LanguageFunctions extends Databaseclass
         public LanguageFunctions()
         super();
         LanguageDetails getDetails(String X)
              LanguageDetails objLanguageDetails=null;
              try
              Statement st=con.createStatement();
              ResultSet result=st.executeQuery("Select languageName From LanguageMast Where           
              languageNo='"+ X +"';");
              objLanguageDetails=new LanguageDetails();
              objLanguageDetails.languageName=result.getString("languageName");
              objLanguageDetails.languageNo=result.getString("languageNo");
              catch(Exception e)
              System.out.println("Cant Get Details");
              return objLanguageDetails;
         LanguageDetails getAllDetails()
              int i=0;
              LanguageDetails vArray[]=null;
              LanguageDetails objLanguageDetails=null;
              try
              Statement st=con.createStatement();
              ResultSet result=st.executeQuery("Select * From LanguageMast;");
              while(result.next())
              objLanguageDetails=new LanguageDetails();          
              objLanguageDetails.languageName=result.getString("languageName");
              objLanguageDetails.languageNo=result.getString("languageNo");
              vArray=objLanguageDetails;
              i++;          
              objLanguageDetails=null;
              catch(Exception e){
              System.out.println("Cant Get All the Details");
              return objLanguageDetails;
         boolean saveDetails(Vector X)
              LanguageDetails objLanguageDetails=null;
              Vector objVector=null;
              objVector=X;     
              String vlanguageName;
              String vlanguageNo;
              try
                   objLanguageDetails=new LanguageDetails();
                   objLanguageDetails=(LanguageDetails)objVector.elementAt(0);
                   vlanguageName=objLanguageDetails.languageName;
                   vlanguageNo=objLanguageDetails.languageNo;
                   Statement st=con.createStatement();          
    ResultSet rls=st.executeQuery("SELECT * FROM LanguageMast WHERE languageNo='"+vlanguageNo +"'");
                   if (rls.getRow()==0)
                   rls.moveToInsertRow();
                   rls.updateString(vlanguageName,"languageName");
                   rls.updateString(vlanguageNo,"languageNo");
                   rls.insertRow();
                   else
                   rls.updateString(vlanguageName,"languageName");
                   rls.updateRow();     
                   return false;               
              catch(Exception e)
              System.out.println("Cant SAVE the Details");
              return true;          
         public static void main(String as[])
              Vector Y=new Vector();
              LanguageFunctions.saveDetails(Y);
    so tell me..what is the solution for this and hw do i get the Stack trace..waiting for ur replies
    Take care.
    Rahul.

    Do you want to print the stack trace of the exception being thrown?
    Use: Throwable.printStackTrace()

  • CIN stack overflow error

    Im using an recursiv c++ function in my VI.
    After severall calls the VI crashes, printing an
    stack overflow error.
    I already increased in Visual Studio 6.0 the Link
    setting: allocate stack. But nothing changed.
    I need help fix this problem!!
    My prg. looks like this:
    recursiv (....) {
    int array[..][..][..];
    recursiv (..);
    Sent via Deja.com http://www.deja.com/
    Share what you know. Learn what you don't.

    > Im using an recursiv c++ function in my VI.
    > After severall calls the VI crashes, printing an
    > stack overflow error.
    > I already increased in Visual Studio 6.0 the Link
    > setting: allocate stack. But nothing changed.
    > I need help fix this problem!!
    >
    > My prg. looks like this:
    >
    > recursiv (....) {
    > int array[..][..][..];
    > ....
    > recursiv (..);
    > }
    If you are truly allocating a three D array of ints
    on the stack, then it makes sense that you will run
    out of stack space sooner or later. I can't help
    you with increasing the stack size, but if you move
    your array into a memory block and store the pointer
    on the stack, then you will use less stack space and
    avoid the problem.
    In otherwords:
    recursive() {
    int *array;
    array= DSNewPtr()
    array[][][]= ...
    recursive();
    DSDisposePtr();
    Greg McKaskle

  • Printing Raise_application_error only for the first one..

    Hi, for each procedure i have a raise_application_error.. But after the first one, each one of the calling procedures print their applicaion error as well. How can I set this up so that only the raise_application_error from the function that's the exception is being raised from?
    Edited by: tolgaek on Jan 17, 2011 10:44 AM

    wonderboy87 wrote:
    Well actually, i'm printing the stack using DBMS_UTILITY.format_error_backtrace appended to my message using raise_application_error,Wrong.
    Therefore I don't need the other calling functions to print theirs,sometimes the stack is so deep that, error message gets cut off where you can't see the most important one.. I just want to make it so that only the first raise_application_error gets printed, which has enough information to debug..Wrong.
    You are mistaken in thinking that turning the error stack into an error text string is valid. A text string is unstructured data. An error stack is structured.
    And despite the fact that you can turn the error stack into a text error message, does not mean that the error stack no longer exists and no longer will be processed (and possibly displayed/printed) by the client that made the call.
    There's also a reason for having an error stack and having a separate error message. The former is for code, debuggers and developers to make sense of - this explains the exact status of the call stack at the time of the error. The latter is the nice-human-readable-message that is for end-users and managers and the like. This explains (or should) the business/logical reason of the error.
    It makes no sense to whack the error stack as text into the error message. What for? How does this make the exception any better to process or understand?

  • Get stack trace into a string with CLDC

    I want to get the stack trace of an application into a string, so that I may print the stack trace elsewhere.
    CLDC api does not have a printStackTrace(PrintWriter pw) or printStackTrace(PrintStream ps) which is present in j2se.
    Could you please suggest another way in CLDC to obtain the stack trace into a string.

    Set System.err to your designated PrintStream and then call Throwable.printStackTrace().
    This will do what you desire.
    rob,

Maybe you are looking for

  • Creating a mask for field input

    I have a cfinput that requires the serial number for a piece of equipment.  The number is always something like J123M456789 where the J or the M could be any letter and the 123 and 456789 could be any number that is 3/6 characters.  The code i am usi

  • How To- Hyperian Performance suite 8.3

    Hi,We are supposed to use Hyperian Performance Suite 8.3 for reporting with our Windows based application (the coding is to be done in C#.net and backend is MS SQL Server 2000). But we don't know how to create reports with Hyperian Performance Suite

  • Error executing Webdynpro mail program

    Hi, I am using webdynpro code for implementing mail service. I have imported jaxrpc.jar as external jar file. I got this jar from axis.zip. While implementing the code, I get following exception. java.lang.Error: Unresolved compilation problems:     

  • TS5181 I downloaded a song but even after the download is complete, it only plays one second of the song and then it ends.

    I downloaded a song to from iTunes, but even after the download is complete it only plays one second of the song and then it ends. Any ideas?

  • I just can't solve this Photoshop graphic problem

    Greetings... I've seen a bit hereabouts on graphics import problems, but nothing so far has led me to a solution. Here's the thing: A multi-layer graphic was created for me in Photoshop CS2. It has a backround image and text. I intend to use it as a