Help:A question about stack

Hi, I met a weird problem,
try {
Stack stack=new Stack();
stack.push(a);
stack.push(b); //a,b are Objects
while(stack.peek() instanceOf Objects)
stack.pop;
System.out.println("Done")
}catch(Exception e) {
System.out.println("Error");
It could be worked, however, I always got the error message, which is so weird.
Can anyboy tell me the reason? Thanks a lot!
Iris

Try the following program:
import java.util.Stack;
public class StackTry
     public static void main(String args[])
          try
               Stack stack=new Stack();
               Integer a  = new Integer(10), b = new Integer(11);
               stack.push(a);
               stack.push(b); //a,b are Objects
               while(stack.peek() instanceof Object)
                    System.out.println(stack.pop());
               System.out.println("Done");
          }catch(Exception e)
               e.printStackTrace();
               System.out.println("Error");
}The problem is when u are doing stack.peek()
After all the elements in stack are poped, stack.peek() is done in the while loop which causes exception to occur. Hence the Error message.
Put a condition to check whether the stack is empty before peeking into the stack.
This should help, i guess.
Manish.

Similar Messages

  • Question about Stacking

    Hello Everyone,
    I have a quick question about stackwise plus technology. I would like to confirm that there is no redundancy at the ethernet switch port in terms of a physical problem. The reason I ask is that we are deploying stacked switches shortly to ensure high availability but curious to know whether anyone has seen issues with physical ports failing and not the chassis/PSUs. I understand that Etherchannels can be used but we have security cameras that cannot suffer any outages and would be connected to a single port on the stack. I'm guessing that my option is to monitor the Switch Ports statistics via SNMP and move the camera to another port if this ever happens.
    Thanks in advance.
    Cheers.
    Evan

    Disclaimer
    The Author of this posting offers the information contained within this posting without consideration and with the reader's understanding that there's no implied or expressed suitability or fitness for any purpose. Information provided is for informational purposes only and should not be construed as rendering professional advice of any kind. Usage of this posting's information is solely at reader's own risk.
    Liability Disclaimer
    In no event shall Author be liable for any damages whatsoever (including, without limitation, damages for loss of use, data or profit) arising out of the use or inability to use the posting's information even if Author has been advised of the possibility of such damage.
    Posting
    Sure, ports can fail without the whole switch failing, but edge redundancy, such as using dual links (often configured as a bundled channel), between the host and two stack members addresses both switch port failure and stack member failure.
    Unless your security cameras support dual links, your going to have a single point of failure at the edge port.
    Next best options, as you've already noted, would be to have, on-line, "warm" spare ports that you can quickly repatch into.  Ideally you have enough spare ports to allowing repatching in case a whole switch member fails.
    (BTW, when you have spare ports, you don't have to set aside a whole stack member, sitting empty.  For example, instead of having a dual stack with only one switch member populated, and the other not at all, split the populated ports across both stack members.  That way, if a stack member fails, you don't lose all your hosts, only half.  [With cameras, depending on their views, you might be able to overlap their coverage across multiple stack member.])

  • Question about stacked graph from DB

    Hi There.
    Ive come up against an interesting issue in my current project. In my prototype I have a stacked column chart (just one column) with the 'sections' of each column being defined as in the Flex docs, i.e. I have 3 column series I will call col1, col2, and col3. This works great but now my problem is that when I start getting data from the DB, I could have any number of column series as I have in the DB data pairs in the form of; col1 - 23, col2 - 34, col3 - 14... And there can be x number of records. Has anyone got any references or ideas about how to go about this?
    Thanks in advance.

    Getting on with this I can say I have made (some) progress.
    The file looks as follows:
    <mx:ColumnChart id="columnChart" type="stacked" dataProvider="{this.chartData}" width="507" height="100%" x="781" y="0">
         <mx:horizontalAxis>
              <mx:CategoryAxis categoryField="category" dataProvider="{this.chartData}"/>
         </mx:horizontalAxis>
    </mx:ColumnChart>
    And the AS part:
    private function createChartSeries(event:ResultEvent):void
         var temp:ArrayCollection = event.result as ArrayCollection;
         chartData = new ArrayCollection();
         var i:int;
         chartData.addItem({name:"val1"});
         chartData.addItem({name:"val2"});
         for (i = 0; i < temp.length; i++)
              var series:ColumnSeries = new ColumnSeries();
              series.xField = "name";
              series.yField = temp[i].call_type.toString();
              series.displayName = temp[i].call_type.toString();
              chartData.getItemAt(0)[temp[i].call_type.toString()] = temp[i].cost;
              chartData.getItemAt(1)[temp[i].call_type.toString()] = temp[i].duration;
              columnChart.series.push( series );
         columnChart.dataProvider = chartData;
         columnChart.invalidateSeriesStyles();
         columnChart.series = columnChart.series;
    [Bindable]
    public var chartData:ArrayCollection;
    The event.result is as follows:
    [{type:"t1", val1=10, val2=30}, {type:"t2", val1=20, val2=3}]
    Now call the "createChartSeries" function the y-axis updates, there are 2 columns (well the grey bit down the bottom), but there are no names (the x-axis values) and the actual data columns do not show up.
    Can anyone help me with this one?

  • Question about stacks

    i've been with aperture since 1.0 so forgive my ignorance on this. I vaguely remember pre 2 that with stack you could do a search (either keyword, star, or whatever) and it would list all the photos that match that and the one in stacks you could open the stack and view the ones that weren't part of the search.
    Let me try to explain my problem, perhaps that will help with the understanding. I have a fairly large library, a bit over 50,000 photos. there are hundreds of folders and projects and everything is very nice and neat. I have keywords and ratings on most of the images in my library, but I'm running into an issue regarding images in stacks that are not keyword or rated.
    as an example, let's say I have a stack that has five photos in it, each rated one through five, with five being the stack pick. The stack is collapsed and life goes on only later I do a search for say all the 3 star or greater photos. In that search there are times when I want to open up the stack and see the rest of the photos to, in case say I wanted to upgrade the rating on something I'd missed.
    Case i point, I have a smart album right now that's looking for photos with a certain keyword. The album has 'about' 300 photos in it. I say about, because roughly half of those are stacks. My problem is I want to add the same keyword to all the photos in the stacks but I can't view the other photos in the stacks because they don't have that keyword.
    I would really like to figure this out. Anyone have any suggestions or hints. Maybe I'm just missing the button or not seeing some setting that I'm supposed to click

    The notion of "stacks" only has meaning in the context of a project, IMO. It was originally part of the Ap design as a means to keep light-table work habits a part of Apple's digital workflow solution. I find it most useful during culling/selection, but not much beyond that point.
    What you are attempting to do is very reasonable, but in my experience the only way to do this is to visit each respective project as you find candidates with your global rating search. It would be easier if Ap allowed a "reverse" lookup directly from a selected image....maybe in Ap3??
    I know this is not an attractive option for you, so maybe others will have a better suggestion.
    Good luck.
    cheers,
    david

  • Need help with question about Microsoft Excel?

    I have recently begun using Microsoft Office for Mac. My question is related to the Excel program. I have used this for years on a PC where when the program opens, it shows a Workbook with a single page. However, on the Mac, when it opens, it shows many pages, the first going from column A to G, the second going from H to N, etc. and each page with the text "Click to add data". This continues forever. I would like to have just one sheet as on the PC. I have not found a way to limit this view to a single page. I have looked in the Preferences and in "View", but nothing seems to change the configuration. Any suggestions?
    Thanks

    My zoom only shows the magnification and does not give a "one page" option. However, I did find an icon that I loaded into the menu bar which gives the one page view. This may be due to the version 2004 that I am using.
    I also find that if I want to change the number of columns and rows, I change the size of each. I assume this is correct.
    Thanks for the help. This is slightly different that the PC version, but I am sure over time, there will be no problem.

  • Please help, simple question about Smart Playlists and Live Updating

    PLEASE for some reason I've never gotten an answer on this.
    I have a Smart Playlist called "Recently Played" with Live Updating. No matter how I set the parameters, the most recently played *song will ALWAYS appear on the bottom of the list when using my iPhone on the go.* I bolded that because I want you to be aware I'm not talking about on iTunes - I'm aware you can change how the list is viewed on iTunes.
    When using your iPod/iPhone on the fly and Live Updating is enabled, is there any way to make the most recently played song appear at the very top???
    Thanks so much

    Haven't seen that problem before but try the following: in iTunes, right-click the playlist name and enable the option "Copy to Play Order." Then sync.
    The normal use of "Copy to Play Order" when you have the playlist displayed in iTunes in some sort order, but you want it to display in the iPod in shuffled order (as it will actually play). Different problem than you are observing, but the same thing "might" help.... Let us know.

  • Question about stacked canvas disappearing

    Hi,
    I have a block which has some database items and non-database items. Since
    there are many items in the block, I use a stacked canvas with horizontal bar
    to display the less important items.
    In the trigger of new-block-instance, show_view('stacked_canvas')
    But I face one problem. When I click on a non-database item and then move
    the cursor away from the item, the stacked canvas suddenly disappears.
    Any idea ?
    Many thanks in advance

    Imagine each canvas as a piece of paper stacked on a desk. Each piece of paper possibly has a different size and the top left corner of each piece is possible oriented in a different spot. When you say show_view('stacked_canvas') its like reaching to the bottom of the pile and putting that canvas top. When you click on an item not on the stacked canvas that items canvas is placed on top. Your problem is that your non-database item content canvas is covering up the stacked canvas. I think...
    Your issue could be solved by simply rearranging the canvas order by putting the stacked canvas last (I think) in the object navigator.
    Raise on Entry could also be causing your issue. Go to the help. Click the search tab. Type "raise on entry". Read "Working with the Raise on Entry Canvas Property". There is a good explanation in there on how stacked canvases get covered up by content canvases and when.

  • Please help..question about sending pdf file from my ipad to another

    I have a pdf file in Kindle that shows up under documents. I am wanting to locate it and send it from my ipad to another..whether through email or even share through kindle. I contacted kindle and they said I have to contact apple with instructions to retreiving the pdf before I can send it. Anyone know how to do it. It shows up in docs on my kindle app but doesnt show up in itunes or on amazon. Help appreciated!!!!

    I copied this from another discussion - that ironically enough - James and I both participated in. The OP never responded to what I suggested, but I think that this may work.
    I think that the Kindle app uses file sharing so see if you can transfer the files to the computer via iTunes with file sharing.
    iOS: About File Sharing
    Then drag the pdf file from the file sharing window (or use the save to button) onto your desktop. Email it from there and you can even email it to yourself on the iPad and store it any other other PDF app that you may have.

  • Please help! --Question about lauching application by JavaWebStart

    Hi,
    I am a new user of the Java Web Start technique. When I tried to launch my application by it, I got the error of
    javaw.exe -- Application error
    "the instruction" at "0x5006bf974" referenced memory at "0x000000e7f". The memory could not be "read"".
    Could anyone tell me what is the cause of this problem and how to fix it? Many thanks!
    Ling

    I'm having the same problem. Specs are:
    Win2K SP2
    IBM Pentium 4 1500 MHZ 512MB RAM
    Java Web Start 1.01
    JRE 1.2.2 and 1.3.1_02 and 1.4.0_01 (setting default to any of these results in the same problem).
    Any help is appreciated.
    Lon

  • Need help with question about upgrading phone

    Okay, so, here's what's going on:
    I currently have a Samsung Galaxy Nexus on Verizon.
    It's dying/freezing/battery life is terrible. Looking to upgrade.
    I don't have an upgrade available for my line, but my wife does.
    She's giving me permission to use hers, which a Verizon rep told me is fine.
    I want to use her upgrade to get a Samsung Galaxy Note II.
    The best price (subsidized) right now is on Dell's site ($169.99), which I could price-match at Best Buy (employee confirmed this). However, it's still a little high for me.
    I could get a better price by adding a line with this device - shave off $40 ($129.99).
    So here's my question: is there any way to add a line, get some immediate savings on the purchase, then immediately cancel the line (maybe only taking a little bit of a hit, getting most of the cost reimbursed for not using it)? In other words, how can I get this phone as cheap as possible?
    Thanks for your suggestions!

    If you add a line as you suggest, that new line will come with a 2 year (24 month) contract for service that will have a $350 Early Termination Fee (ETF) if you cancel the line immediately like you indicated.  There goes the thought of getting the Note II for the cheaper than the upgrade price.
    I recommend going with the price match upgrade @ $169.99 at Best Buy.  I can confirm they do the price match.  I bought my last phone from Best Buy and they matched the Radio Shack price I brought them and  I had a good experience.
    Good luck.

  • Need help with question about indesign 2014...

    I am using indesign 6 on a pc - simple question: when I update to indesign 2014, will the update keep all of my previous and current work?

    Yes. Your documents will be unaffected by any new versions you install unless you open them in the new version and save them with the same name, then you will lose the ability to open them again in the old version.

  • Help! Question about Java Server Pages

    Hi everybody!
    I'm new to Java, and I wonder if anybody could help me with this:
    I need to know the "extension" of this file (I don't physically have the file, I have only its contents!):
    </GX>
    <GX ID=Beetle>
    <BR>
    Thank you for choosing <GX TYPE=cell ID=common.Title></GX> for your travel arrangements<BR> <BR>
    <GX TYPE=tile ID=resInfo>
    Reservation Information<BR>
    Reservation Number: <GX TYPE=cell ID=resInfo.recLoc></GX><BR>
    </GX>
    <BR>
    <GX TYPE=tile ID=buyer>
    Billing Address<BR>
    Buyer: <GX TYPE=cell ID=buyer.name></GX><BR>
    <GX TYPE=cell ID=buyer.isResPhone> Residence Phone: <GX TYPE=cell ID=buyer.rPhone></GX><BR></GX>
    <GX TYPE=cell ID=buyer.isBizPhone> Business Phone: <GX TYPE=cell ID=buyer.bPhone></GX><BR></GX>
    <GX TYPE=cell ID=buyer.isFaxPhone> Fax Phone: <GX TYPE=cell ID=buyer.fPhone></GX><BR></GX>
    Address: <GX TYPE=cell ID=buyer.addrOne></GX><BR>
    <GX TYPE=cell ID=buyer.isAddr2> <GX TYPE=cell ID=buyer.addrTwo></GX><BR></GX>
    City: <GX TYPE=cell ID=buyer.city></GX><BR>
    <GX TYPE=cell ID=buyer.isState> State/Province: <GX TYPE=cell ID=buyer.state></GX><BR></GX>
    Country: <GX TYPE=cell ID=buyer.country></GX><BR>
    <GX TYPE=cell ID=buyer.isPostal> Postal/Zip Code: <GX TYPE=cell ID=buyer.postal></GX><BR></GX>
    </GX><GX VISIBLE=false> <!-- end of buyer tile --> </GX>"
    After many searches on the web, I can't find out if it's a HTML or GXML template, or if it has to do with JSP (is it a .jsp web page?)
    Thanks in advance!

    Thanks very much both of you for your prompt help!
    I had already found this link but now with your explanations, it seems a bit clearer now...
    After another search, it seems that this file is a HTML or GXML template to be rendered by a template engine (I've read that GXML templates only contain GX tags like my file) . Does it sound familiar to you?
    I need now to know which extension would have this file it is were like I believe a HTML or GXML template? Will it have simply a .html or .gxml suffix?
    Many thanks in advance!

  • Question about stacked objects using blend modes

    Say there are three stacked objects. The two topmost have a blend mode.
    In the area where all 3 intersect, the bottom object interacts with the transparency. Is there a way to limit how many levels the transparency affects? If you could limit it to two levels, then in the area where all three intersect the bottom object wouldn't participate in the blending. But in the areas where it overlaps only one of the topmost objects, it would participate.
    I know this can be achieved by creating another object, or using the Pathfinder, I'd just like to know if there is a simpler method to use.

    The attached PDF explains this better. Page 1 - the yellow and magenta are multiplied on top. But the cyan in not participating in the area where all 3 overlap. But in the areas with only 2 levels, it does participate, so there are the green and blue overlaps.
    Since the cyan is negated from the one area, the result is red – yellow and magenta multiplying
    The problem is, the only way to get this is to punch a hole in the cyan. So when you move the yellow and magenta around, the red doesn't follow (see page 2)
    It would be nice if the blend modes included some sort of level limit. Default would be unlimited, but you could change it to 2 or whatever number you want. In this case if the level was 2, no hole in the cyan would be required.
    As far as I know Adobe has not added to transparency capabilities for a long time. You have the 16 bend modes, and opacities. And knock out group and isolate blending, which are good features. But maybe it's time to expand on this and add more points of control.

  • Question about Stacked Chart ... is this possible?

    This seems possible but I cannot get APEX to do it, wondering if someone has any ideas:
    Say I have a table with multiple records with columns which contain a DATE, PERSON, TEAM ...
    I am comparing number of records per team but trying to show in the STACK how each person contributed ...
    Lets say there are 5 teams ...
    I want to end up with a STACKED BAR chart which shows HOW MANY INSTANCES (count(*)) per TEAM ...
    I want to end up with 5 BARs and each subdivided with the number of record instances which each PERSON in that team.
    So at the end of the day, we can see how different people contributed to the overall total of a team and we can see how each team fared against one another ...
    Thank you!
    C

    You would build a series per team and group on your date value with same aggregate.
    Sample series using EMP and DEPT tables.  seen here  Chart Axis
    Series 1
    select null link, TRUNC(e.HIREDATE,q') label, count(*) acct
    from  "EMP" e natural join "DEPT" d
    where d.dname = 'ACCOUNTING'
    group by TRUNC(e.HIREDATE,q')
    Series 2
    select null link,TRUNC(e.HIREDATE,q') label, count(*) sales
    from  "EMP" e natural join "DEPT" d
    where d.dname = 'SALES'
    group by TRUNC(e.HIREDATE,q')
    Series 3
    select null link, TRUNC(e.HIREDATE,'q') label, count(*) research
    from  "EMP" e natural join "DEPT" d
    where d.dname = 'RESEARCH'
    group by TRUNC(e.HIREDATE,q')
    Regards,
    Brad

  • Question about stacked sequence structure

    Hi,
    I made a numeric control outside a stacked sequence structure, and connect the control both to frame 1 and frame 2. In frame 2 there is a while loop structure. And now I start the labview program with the control A. Then, after frame 1 finished, frame 2 started, now I want to change the control to B and deliver B into frame 2. But the indicator in frame 2 shows that the control is still A. So I wonder how can I change the control and deliver it to the frame after the frame has started? Thank you!
    NI Software :  LabVIEW  version 7.1
    OS :  Windows XP
    Regards,
    jackauden

    Dataflow dictates what you are seeing. The control does not get read once the sequence starts. This is as expected.
    Some possible solutions:
    Just don't use stacked sequence! I don't and never feel limited by this choice.
    Create local variable of the control and read from it inside frame 2.
    Do you REALLY need a stacked sequence? Why???
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • Unable to connect DV camera

    Using FCE HD 3.0, Sony TRV 110 (approved camera). Since upgrading QT 7.1.2 Pro, cannot see camera in FCE or iMovie. Tried the "remove old .pkg" fix in Library, this did not correct problem. Cannot see camera even after using Easy Setup. Also switched

  • Moving bars In score

    Anyone else having problems moving bars downward in the score window. It seems they only go up even when you grab and pull them down. I've set the max limit in score preferences. Perhaps just another score bugger in 8.01.

  • Air or Pro for academics

    Hi, I am starting my PhD this fall in Chemistry, and am trying to decide between the Macbook Air and the Macbook Pro. I'll need it for writing my dissertation, research, and other academic-related uses; not movies or games. I hear the flash memory in

  • Modifying request before approval

    Hello Friends, I want to allow modification to the request before Manager Approval. Once it is approved user/admin should not be able to modify request. how to achieve this. If have any sample code snippet, then please, give me. Thanks and Regards DB

  • RSIMPCURR to run for multiple R/3 systems

    We have one BW system being fed by 3 different ECC systems.  Each ECC system has it's own table of currency exchanges.  One system converting to Euros, a second system converting to British Pounds and a third system converting to US Dollars.  We need