-2

I want to let my program do something when i have this error: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "lekker hoor". Can someone help me with this?

I want to let it open a Joptionpane when this error happens whit the text: Dont use letters or spaces. Only use numbers.

Kruti Patel
  • 1,422
  • 2
  • 23
  • 36
  • 5
    try catch ? https://docs.oracle.com/javase/tutorial/essential/exceptions/catch.html – Reigertje Dec 11 '15 at 08:46
  • 1
    Have you looked online at all? Try looking into something like: https://docs.oracle.com/javase/tutorial/essential/exceptions/ – Callan Heard Dec 11 '15 at 08:46
  • There u can find another solution [stackoverflow.com::how to check if a string is numeric in java](http://stackoverflow.com/questions/1102891/how-to-check-if-a-string-is-numeric-in-java) – Raimbek Rakhimbek Dec 11 '15 at 09:50

1 Answers1

2

Use try catch block:

try {
  //your code....
} catch (NumberFormatException e1) {
  // Open your JOptionPane Here
}
ThisaruG
  • 3,222
  • 7
  • 38
  • 60
  • 1
    Don't catch `Exception` unless something in the try block actually throws `Exception` specifically. – Andy Turner Dec 11 '15 at 08:58
  • @AndyTurner Yeah. Thanks. I did put that because if he has any other exceptions to catch. But it was misleading. __Edited__ now. – ThisaruG Dec 11 '15 at 08:59