User Profile

Collapse

Profile Sidebar

Collapse
Jerick
Jerick
Last Activity: Mar 5 '12, 09:58 PM
Joined: Feb 21 '12
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • How can I convert a JTextField that's returning null to a different string value?

    I have a JTextField that I'm not always passing a value to, but it causes an exception to be thrown when the program runs if the person hasn't entered anything into the JTextField. I have some code below that I'm trying to convert a null response into a different String value. Why isn't it assigning stringInput as a String of "0"?

    Code:
                String stringInput = " ";
                stringInput = dinnerTextField.getText();
    ...
    See more | Go to post

  • How can I make a float throw an exception, when entered?

    I have a GUI that I use as a calculator. When I enter in anything other than numbers, it throws a NumberFormatExc eption, as intended. But when I enter in a number such as "23423f" the program seems to think I'm entering a float and doesn't throw an exception, because of the f at the end, even though all other letters throw an exception.

    Currently, all I'm doing is putting the input section into a try catch block, where I parse...
    See more | Go to post

  • Jerick
    replied to Wrong exception being thrown
    in Java
    Ok, that works. I see what the problem was now. Thanks a lot.
    See more | Go to post

    Leave a comment:


  • Jerick
    replied to Wrong exception being thrown
    in Java
    That looks like it would use the correct System.out.prin t() messages. But the problem is that I've been required to use IllegalArgument Exception.
    See more | Go to post

    Leave a comment:


  • Jerick
    replied to Wrong exception being thrown
    in Java
    I put the -1 there so that if the value doesn't get changed, then that means it didn't get parsed into an int, which means it's a string. If it doesn't go through the for-loop, then the value still isn't changed and it throws the exception.
    See more | Go to post

    Leave a comment:


  • Jerick
    replied to Wrong exception being thrown
    in Java
    Yup... I added an if else statement to the code I just posted which is why numbers between 1 to 12 aren't working anymore. Simply moving the for-loop into the catch doesn't change anything.

    Did YOU read my first post? I explained all of this. Read the 2nd paragraph in my first post, please.
    See more | Go to post

    Leave a comment:


  • Jerick
    replied to Wrong exception being thrown
    in Java
    In the code I posted, a string like "December" just skips over the empty catch block and goes to the for-loop.

    But here's some code where I entered the for-loop into the catch block. Strings like "December" are working, but if I enter in a number outside of 1 to 12, it passes the 1st IllegalArgument Exception and goes to the 2nd one and gives the wrong System.out.prin t()

    Code:
          public void setMonthName(String
    ...
    See more | Go to post

    Leave a comment:


  • Jerick
    replied to Wrong exception being thrown
    in Java
    With the code I posted, strings such as "January" or "Saturday" were being hanlded correctly, but numbers outside of 1 to 12 were being sent down to the 2nd IllegalArgument Exception instead of the 1st one and giving the wrong System.out.prin t() message.

    If I add a throw new IllegalArgument Exception to the catch block, then numbers outside of 1 to 12 get handled correctly, but strings such as "January" or...
    See more | Go to post

    Leave a comment:


  • Jerick
    started a topic Wrong exception being thrown
    in Java

    Wrong exception being thrown

    I'm trying to account for any value outside of 1 to 12 or a name of a month. I'm passing in a string to this method. I then try to parse it into an int and do an if statement to see if it's between 1 and 12. If it's not an int then it goes down and a for-loop checks to see if it's a name of a month.

    The problem is that if I add a throw new IllegalArgument Exception to the catch block and pass in "Saturday" it throws the Illegal...
    See more | Go to post
No activity results to display
Show More
Working...