0

I did manage to publish my roman numeral converter application onto Google Play and I'm currently making updates to it. You can reference the app in this question I have asked here How to set textView as method output on android

I have replaced the original setText methods with setHint based on this question How to clear a editText on click.

However on my convert button listener when I've changed the try catch statements to setHint

Android Studio says it can result in a NullPointerException.

Here is my code for reference:

try {
    int integer = Integer.parseInt(intValue);
    if (integer > 0 && integer <= 4999) {
        numeralInput.setText(translator(integer));

    } else {
        numeralInput.setHint("Enter an integer from 1 to 4,999.");
    }

} catch (NumberFormatException e) {
    numeralInput.setHint("Invalid input try again.");
}

What can I do to change the hint without result in the exception?

Community
  • 1
  • 1
Rave
  • 51
  • 4
  • 1
    I think you are talking about the android studio warning.. you can just disable it – Muhammad Ashraf Jun 17 '16 at 18:43
  • 1
    `numeralInput` *can be* null because `findViewById` *can return* null. Unless you get an actual error, ignore the warning – OneCricketeer Jun 17 '16 at 18:47
  • 1
    where are you defining `numeralInput`? – Cory Roy Jun 17 '16 at 18:47
  • Simple solution is to put an if statement to check to make sure numeralnput is not null and the warning will disappear. – SierraMike Jun 17 '16 at 19:33
  • @MuhammadAshraf I understand I can disable the warning but I want to understand it better before doing so. – Rave Jun 17 '16 at 19:46
  • @cricket_007 I know that I can just ignore the warning but thanks for the explanation! – Rave Jun 17 '16 at 19:47
  • @Cory Roy it's defined earlier in the program where I've defined the buttons and TextView. – Rave Jun 17 '16 at 19:47
  • @Sean McDonald Thank you for the help! – Rave Jun 17 '16 at 19:47
  • @Rave So it's done in the `onCreate()`? It's just I've never seen this warning before so I wonder if it's possible that you are declaring it conditionally. – Cory Roy Jun 17 '16 at 20:24
  • @CoryRoy That can be a possibility, since this is the first time I've used hint in my program. I wanted to change the hints so I assumed that using setHint() method would work. – Rave Jun 19 '16 at 17:12

0 Answers0