• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exceptions Java Form 2D array list  RSS feed

 
Jayden Brymatt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • 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!
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!