Catch Negative Number

Hi experts,
Is anyone can teach me how to catch negative input in GUI. I use NumberFormatException but it only catches String. I'd like to know in either way (try-catch and throwing exception.
private void btnEnterActionPerformed(java.awt.event.ActionEvent evt)
String amount = txtAmount.getText();
if(!amount.equals(null) && !amount.equals(""))
try
double balance = depositTransaction.deposit(Double.parseDouble(this.txtAmount.getText()));
lblBalance.setText("Your account balance is: $" + balance);
catch(NumberFormatException e)
lblBalance.setText("Invalid deposit entry");
txtAmount.setText("");
btnEnter.setEnabled(false);
Thanks heaps.

There is no exception for negative numbers, because negative numbers are not exceptional when parsing for numbers.
Don't try to handle with with an exception, or in the catch block. Try to parse the string to get a number. If it fails with a parse exception, tell the user. If it doesn't fail, then after parsing, check to see if the number is negative. If it's negative, then tell the user. You'd do this in the try block not the catch block.

Similar Messages

  • Thread Running negative number of time.

    Hi All,
    I wrote a program to check the effects of Thread priority, however to my surprise the output is weired the higher priority thread shows that it run negative number of time, below is the code.
    package javaProg.completeReferance;
    class Clicker implements Runnable
         Thread t;
         int click;
         volatile boolean  running = true;
         public Clicker(int pro)
              t=new Thread(this);
              click = 0;
              t.setPriority(pro);
         public void run()
              while (running)
                   click++;
         public void start()
              t.start();
         public void stop()
              running=false;
    public class TestClicker
         public static void main(String [] args)
              Clicker thread1 = new Clicker(Thread.NORM_PRIORITY+2);
              Clicker thread2= new Clicker(Thread.NORM_PRIORITY-2);
              thread1.start();
              thread2.start();
              System.out.println("Processing");
              try
                   Thread.sleep(10000);
              catch (InterruptedException i)
                   System.out.println(i);
              thread1.stop();
              thread2.stop();
              try
                   thread1.t.join();
                   thread2.t.join();
              catch (InterruptedException i)
                   System.out.println(i);
              System.out.println("The number of Time Thread1 executed is "+thread1.click);
              System.out.println("The number of time Thread2 executed is "+thread2.click);
    }Here is the Output..
    C:\Users\pravin>java javaProg.completeReferance.TestClicker
    Processing
    The number of Time Thread1 executed is -386946835
    The number of time Thread2 executed is 837375311Thanks!!

    Thanks a lot , I changed int click to long and its
    working fine.I am wondering why the Java Platform
    didnt throw an error or exception for overflow.Because the Java specification calls for it not to do that but instead to do what you saw and rollover.

  • How to find Negative number

    can any one pls tell me how to find negative number ?
    Thanks

    1. One easy method is to look for the giveaway dash in front of the number, e.g. "-1" is a negative number, given the "-" instead of the "1."
    2. Negative numbers can also sneakily be found by multiplying i by itself: i^2^ is a negative number.
    3. Negative numbers can hide in the exponent of e as complex numbers. e.g. e^i*pi^ is a negative number.
    4. If we're referring to Java here, perhaps the following could be of some use:
    final int ZERO = 0;
    public static void main(String[] args) {
    int a = 3;
    int b = -13;
    System.out.println(a + " is negative? " + lessThanZero(a));
    System.out.println(b + " is negative? " + lessThanZero(b));
    boolean lessThanZero(int n) {
    return n < 0;
    }

  • PO_QTY came out with 0 and negative number

    Hi experts,
    I was loading data via 2LIS_02_SCL,2LIS_02_ITM. PO_QTY was populated by ABAP instance. But some PO_QTY number came out with zero and negative number while some of other PO_QTY number came out with the right number.
    I was working on this problem for 2 days but have no idea on it. Anybody can help me?
    Thanks a lot.
    Junbo

    dear Junbo,
    are you working with business content extractor only, i mean no enhancement to that field ? i think it can be 'program error' that po quantity is not correct, try to search oss note ? what's your r/3 PI level ? applied the oss note mentioned before working with lo-mm pur ? it's stated in mm pur extraction doc (if you have not this doc, let's know your email, will send you).
    if you are using business content extractor only without enhancement to this field, you may create oss message to get sap help. debug with rsa3 option debug marked is possible.
    hope this helps.

  • Problem to display a negative number in XML Publisher output in excel

    Hi All,
    I am facing problem in displaying a negative number in XML Publisher output in excel.
    My requirement is that I have to display a negative number in brackets when the output is taken in excel format. Eg: If the value is -123 then i have to display it as (123).
    I have put these brackets using a formula column in the RDF, but it is the default functionality of excel that whenever there is a number in brackets then it automatically displays that as a negative value.
    Can anyone please help me how I can display this negative number within brackets and not as a negative digit. Is there any special tag or is there any formula which can be used to convert this into text and written in the Help text of RTF template.
    This is very urgent. If someone knows please reply asap.
    Regards,
    Shruti

    This is very urgent. If someone knows please reply asap.We are all volunteers here, so no ones questions are more urgent then other ones.
    If its that urgent it would have helped if you had chosen the correct forum to ask your question BI Publisher

  • How do I thin a font in CS6? I tried a negative number in offset path and it didn't work.

    Hi!
    first time here. I posted this question in community guidelines by mistake, oops.
    Any help would be appreciated!
    I tried this with outlining the font and also without. The negative number in offset path doesn't thin, however if I do a preview and put in a positive number it does add onto the width of the font.
    Thanks,
    maryann

    I am going to share with you the secret to using type with appearance. After setting type change the fill to none(characheter level), then add a fill(type level). This way you do nto have 2 fills fighting with each other.
    Below I did not follow my advice to better explain what is happening, but I chose a different color fill. Even though I only have one fill, there is a black stroke coming from the character level.
    To salvage your existing type, double click so you select all the type with the |-Beam, your appearance palette will now say characters, and delete that fill.
    When you oultined your fonts, most likley the same thing happened, but a battle battle between the path and group level.

  • Change negative number for total amount in BP aging detailed report in PLD

    Dear Expert
    In BP aging detailed report, the total amount field display as
    -1,000.00
    May I know how to change the negative number format as
    (1,000.00)
    This is formula field.
    Thanks.

    Hi All,
    The settings can be changed from BeX (Query Designer or WAD).
    Please click on the Settings link in the generated report (either from Query Designer or WAD) and go the Data Provider tab.
    There is a header called Number Format and a drop down Display of +/- signs:, select different options from the drop down.
    Thanks and Regards,
    Arya

  • Negative number cannot be displayed in table if the column is too narrow

    Hi, All
    When a number is formatted  as a certain formatting(not locale formmatting),Negative number cannot be displayed in table if the column is narrower than the negative number, just minus is displayed.
    Can you help me? Thanks.
    Version: EHP1 for netweaver 7.0 SP3
    Best regards,
    Jiande Ding

    Hi,
    I think this has nothing to do with positive and negative numbers, By default the alignment of the text is Left, if you dont want to see '-' sign initially then you can change the alignment of the text to center or right in the display tab of properties for that column.
    As you as saying that at runtime the numbers are visible if manually adjusted. to icrease the width of that column permanently goto Layout tab of the story board and increase the size of the table and then increase the width of the column.
    the Fit Contents in the Layout should be set to "Actual Size".
    Regards,
    Rk.

  • My mountain lion upgrade is take long after the initial installation finish it is showing increasing negative number like -50 munites remaining

    My mountain lion upgrade is take long after the initial installation finished it is showing increasing negative number like -50 munites remaining while still saying installing os x on the disk.
    I mean it starting saying time remaining about 6 munites
    Now it up to time remaing about -55 munites
    I thing something is wrong with this installation and all I did is fallow the onscreen instruction
    Thank

    You might want to just manually power down your machine and, if necessary, start the installation process anew. You're unlikely to damage anything by doing this. It may have actually installed and is just hanging when it's supposed to reboot.
    Good luck,
    Clinton

  • Use array to store negative number

    Hi,
       I use "Initialize array" to set all the 500 elements to "0". Then I input numbers to  "Replace Array Subset"  and generate a new array. But all the positive numbers are correct, negative numbers just become "0". Why? How can I store the negative number in this array?
       Thank you in advance!

    Hi,
    what data type (numeric representation) are you using for the array elements? If it is integer, make sure it's not unsigned (U8, U16, ...) as this data type doesn't allow negative numbers.
    Hope this helps

  • In MyVerizon, my current bill ballance is a negative number. What does that mean?

    It's a negative number, and it's red, instead of black like it usually is.  It also says my bill was paid in full on the 27th of December (autopay), but there was nothing on my bank account reflecting that.  What's up with that?

    If your balance due is in the negatives that means that you have a credit balance (i.e. VZW owes you money), that will normally be deducted from your next bill. As for your bank not reflecting the payment yet, it can take a few days for VZW to actually pull if from your account, but they post payments on their side immediatley.

  • No negative number

    Hi can anyone help how to write a SQL/PLSQL code when an negative number insert a error message should appear??
    ekas

    If this is an APEX item, you should be able to go in to the APEX page and add a validation. You can choose to do an item-level validation-- if you choose to do a function returning error text, you'd just need something like
    IF( :your_apex_item < 0 )
    THEN
      RETURN 'There was an error.  This item must be greater than or equal to 0';
    ELSE
      RETURN null;
    END IF;Of course, you can tailor the message to make it more meaningful.
    Note as well that there is a separate forum for APEX-specific questions-- if you post over there, people will assume that you're asking about APEX not about server-side PL/SQL.
    Justin

  • I submit a negative number and it subracts twice the value

    I submit a negative number and it subracts twice the value on Numbers 08 running Lion

    "But as soon as I paste the two columns(column of names), (column of information) from the original bad sheet into it seems these pastings corrupt my numeric column in some way.  So it seems anything pasted from the original working sheet onto a good new sheet causes the new sheet to have the same problem."
    You might be able to strip that corruption with one of these techniques:
    Export the original document as a CSV file. Open this in Numbers, then transfer the names and information columns (individuallly) using Copy/Paste
    Export the original document as an MS Excel file, Open that file in Numbers.
    Copy the names column from the original document to the Clipboard.
    Select the first cell in the Names column of the new table.
    Use an Applescript to convert the contents of the clipboard to Text and paste it into the new document.*
       repeat with Information column
    Regards,
    Barry
    * I've contacted Yvan regarding a minor edit to a script he wrote some time ago to do this in Pages.

  • Invoice verification (negative number)

    I have a purchase order with 2 item. One of them is a return item with a higher price than the other.
    In the Invoice verification i have the following problem: if the prices from both itmes are added the BALANCE is positive so the AMOUNT should be negative to make the balance 0,  but if i write in the amount a negative number i get an error message "Negative values not allowed".
    Any ideas?
    Regards

    hi,
    you can try this with Subsequent Debit, In MIRO transaction, you do subsequent debit.
    Hope this may help you,
    Regards,
    Srinivas

  • Large Negative Number in Column Chart

    When using a large negative number (eight digits or more) from hierarchical data in a column chart, the browser FREEZES. Has anyone else experienced this? Any suggestions on how to fix? See the sample code below.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            //hierarchical data.
            [Bindable]      
            private var input:Array = [
                { xfield:"World", value:-50000000, children:[
                { xfield:"Asia", value:15, children:[ { xfield:"Bhutan", value:1 }, { xfield:"Singapore", value:5 }, { xfield:"Thailand", value:17 }, { xfield:"India", value:10 }, { xfield:"Japan", value:15 }, { xfield:"Nepal", value:5 }]},
                { xfield:"America", value:30, children:[ { xfield:"Mexico", value:5 }, { xfield:"Brazil", value:8 }, { xfield:"Chille", value:6 }, { xfield:"US", value:25 }, { xfield:"Canada", value:22 } ]},
                { xfield:"Europe", value:20, children:[ { xfield:"Switzerland", value:8 }, { xfield:"UK", value:15 }, { xfield:"Germany", value:15 }, { xfield:"France", value:5 }] },
                { xfield:"Australia", value:23 }
        ]]>
    </mx:Script>
    <mx:ColumnChart id="chart" dataProvider="{input}" height="200" width="254" x="25" y="10">
        <mx:horizontalAxis>
            <mx:CategoryAxis categoryField="xfield" />       
        </mx:horizontalAxis>   
        <mx:series>
            <mx:ColumnSeries yField="value" />
        </mx:series>
    </mx:ColumnChart>
    </mx:Application>

    I am facing exactly similar issue in my project. can anyone help?

Maybe you are looking for

  • Magic Mouse not connecting to MBP after Sleep or Re-start

    This has been an on going problem for me since I upgraded to OSX 10.8 on my MBP.  Since the upgrade my Magic Mouse will no longer connect to my MBP after it has gone to sleep, restarted or shut down.  The only way I have been able to get a connection

  • HELP: How to configure ichat

    I want to use google talk on ichat. what i've done so far. - registered with google talk - downloaded spark - failed to create a new spark/ jabber account using my google talk id. which server i need to fill in here?? talk.google.com??? i'm really st

  • T430 2342CTO - SanDisk 16GB mSATA Target Read Test Fail

    Hi all, my Lenovo Solution Center (LSC) told me that my mSATA had a targetd read test fail.  I ran the test myself and it had the same issue.  Read some threads and tried the LSC test but only tested the SSD, and it passed all tests when ran this way

  • Converting slideshow from iphoto with itune playlist as background music

    I have created a slideshow in iphoto with an itune playlist as the background music and when I convert it throught quicktime into a movie it only plays the first song from the playlist. All photos look good in the slide. This problem has started sinc

  • Dreamweaver CS3 crashing.

    Is anybody else getting problems where Dreamweaver CS3 keeps crashing particularly when trying to transfer files from/to a web server. I'm running it on Vista Ultimate using WebDAV as the transfer protocol, is that makes any difference. Cheers, @ndyB