• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Exceptions Java Form 2D array list

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

This program should generate a form where the user puts in the amount in minutes, greater than 0 and less than 240, and the money earned, greater than 0. Once the user clicks Enter the values should be added a 2D array. When I try and run this program these are the errors that I'm receiving:

There's quite a few more, but the bottom three are the only ones that indicate specific lines. Here is my code:


Can anyone nudge my brain in the right direction to figure this out? I'm thinking something is wrong with Any help would be appreciated.

Thanks.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!


This indicates your array is empty, but you are trying to access the 1st (0 index element)

To solve this, you need to consider a scenario where info might be empty.
In pseudo code
1) Check if info is empty
2) If not, do stuff
 
Jayden Brymatt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maneesh! After looking at the rest of my code, I think there are quite a few things that may need enhancing. It all made sense when I was originally typing it, but looking at it a second time shines a new perspective. Thanks for the nudge
 
Jayden Brymatt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I've got everything working smoothly now, except for one thing. I have to have a couple of exceptions to make sure the minutes entered are greater than 0 and less than 240, and that the earnings entered are greater than 0. Here is my code for this portion, but I keep hanging up:

Any reference anyone can point me too on this? I've tried looking around for examples, documentation and reading but I'm just not getting it. Any nudge is appreciated.
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have outsite the try/catch block. Did you mean to wrap that with the try/catch?
 
Jayden Brymatt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi E Armitage, thanks for looking. Yes I meant to wrap that, thanks for the catch! However, even with that I'm getting stuck in an endless loop I think if I enter a value of 0. I changed to due to 0 is always less than 240 and would satisfy one of the parameters.
 
Marshal
Posts: 80138
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should think long and hard about the conditions when you write loops. The number of queries we see about loops which never start or never stop, because people have given them tautologies or contradictions as their loop conditions!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You should think long and hard about the conditions when you write loops.


@Jayden: you should also not code long lines, especially here.
I'd break yours up myself, but there are tons of them; and it's bad practise.

Winston
 
This tiny ad will self destruct in five seconds.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic