Exception for an unentered value?

In my calculation app, which takes a few inputs and uses them in a fixed formula to produce multiple outputs, the application crashes if I try to run it without putting a value into every input.

I know how to catch exceptions, but I don't know the name of the exception that would be thrown by this kind of error. Can anyone help me out on this?

Asked by: Adelaide889 | Posted: 25-01-2022

Answer 1

Look at the stack trace for the class name of the exception.

If I had to guess, I would say it's probably a NumberFormatException

Answered by: Ryan619 | Posted: 26-02-2022

Answer 2

If you can avoid triggering an Exception, try rewriting your code to check whether those input fields are empty, and if applicable, if those input are numeric. Catching an Exception sometimes is a big performance hit.

Answered by: Abigail496 | Posted: 26-02-2022

Answer 3

I agree it sound like a NumberFormatException happening when your Double.parseDouble(s) fails on an empty or null string.

If you input control allow alpha-numeric input you can (and should) catch this, but for user-friendliness, you should make sure the string isn't empty first. You can then provide two useful error message:

  • "Please enter a value" (if the string is null or blank)
  • "Please enter a number" (if you caught the parser exception)

You might also consider using or building an input control that only allows for correctly formatted numeric input, including never passing back a blank. If you have this sort of control, you should not catch the parse exception since none should happen, and if does, this means there is a BIG problem and you really want to know about it by failing loudly.

If you are using a numeric-only control, then it's probably just that you are getting back an empty string.

Answered by: Cherry725 | Posted: 26-02-2022

Answer 4

Also if you are using an IDE, you can attach source code of SDK and directly lookup the source to see what all exception it throws and where. That way you will be able to handle exception at correct places.

Answered by: Dainton245 | Posted: 26-02-2022

Similar questions

database - getting sqlite exception when insert ? how to?

i created the database like this db.execSQL("CREATE TABLE "+TABLE_NAME+" (" +_ID+" INTEGER PRIMARY KEY AUTOINCREMENT," + TITLE+" TEXT UNIQUE," + PUBLISHED+" DATETIME," + CONTENT+" TEXT," + RATERS+" TEXT," + VIEWCOUNT+" TEXT," + THUMBNAIL+" TEXT," + FAVCOUNT+" TEXT," + FAVSTAT+" INTEGER," + LINKWEB+" TEXT);"); i got an exception when i try to ins...

Is there a way to break into the debugger on exception in Android emulator?

Assuming I didn't start in debug mode, is there a way to make the eclipse debugger automatically start if my app throws an exception inside the emulator? Alternatively, is there a way to get a more useful error message out of the emulator (something more useful than "Sorry, your app terminated unexpectedly").

exception - android View not attached to window manager

I am having some of the following exceptions: java.lang.IllegalArgumentException: View not attached to window manager at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355) at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:191) at android.view.Window$LocalWindowManager.updateViewLayout(Window.java:428) at android.app.Dialog.onWindowAttributesChanged(Dialog.java:...

android Sax parsing exception for "»" character

hi friends i'm using Sax parser for parsing my xml file which i recieve from the internet... The problem is that the normal xml is parsed fine except the xml files which have "»" symbol in the attributes... everytime i try parsing the file i get the following error 02-11 16:57:35.547: INFO/System.out(754): org.apache.harmony.xml.ExpatParser$ParseException: At line 9, column 0: not well-formed (inv...

Sqlite Database LEAK FOUND exception in android?

I am getting this exception in database Leak Found my LOGCAT Shows this: 02-17 17:20:37.857: INFO/ActivityManager(58): Starting activity: Intent { cmp=com.example.brown/.Bru_Bears_Womens_View (has extras) } 02-17 17:20:38.477: DEBUG/dalvikvm(434): GC freed 1086 objects / 63888 bytes in 119ms 02-17 17:20:38.556: ERROR/Database(434): Leak found 02-17 17:20:38.556: ERROR/Database(434): java.lang.Illega...

java - How to handle runtime exception on playing audio files?

I have a button that plays an audio file on its click listener. If the button is clicked again and again while the audio file is being played then the app crashes. What's the solution? Here is some code for reference: private OnClickListener btnMercyListener = new OnClickListener() { public void onClick(View v) { // Toast.makeText(getBaseConte...

exception - How to retrieve brand and model info by code on Android?

There is an class android.os.Build that got static variables cointaining device info, but when i try to access it I allways get a runtime exception. E.x on how I try to access it: String model = Build.MODEL; I always get an Exception like this: 04-14 14:57:45.266: ERROR/AndroidRuntime(770): java.lang.VerifyError: com.mypackage.Main

android - Activity Not found Exception while trying to send a mail

I have written a code snippet to send mail when a button is clicked. But when i click the send mail button i am getting an ActivityNotFound exception in the logcat... Here's the code... public class appointments extends Activity { List<Strings> appnt=new ArrayList<Strings>(); ArrayAdapter<Strings> adapter=null; EditText name=null; EditText phone=null; Date date=null; Spinner spinner=null;...

android - Force close before onCreate, activity class not found exception

I just started testing my app on android 1.5, and it doesn't want to run at all. I have a breakpoint in onCreate on my main activity, but I get a ClassNotFound exception even before reaching that. The class not found appears to be the class of my main activity. The exception happens in: ActivityThread.performLaunchActivity It runs fine on 1.6 and later, so I assume I'm using something that isn't supported on 1....

java - Android camera out of memory exception

I have a strange problem on my htc hero. When launching camera, i get out of memory exception. After that, if i launch any other application that uses camera, they also crash(when trying to use camera function). I call camera.release and camera.stoppreview in surfacedestroyed function, but that doesnt help. What is the right way to release all resources? Could somebody please show his working surfacechanged, surfa...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android