Results 1 to 12 of 12
Thread: Please help me
- 02-21-2013, 12:38 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 19
- Rep Power
- 0
Please help me
iam new to java and i got an error as
Exception in thread main java.lang.arrayindexoutofboundsexception:0 at Runtime.main<Runtime.java:19>
Program:
class Rectangle
{
int length,breadth;
void Displayvalues(int x,int y)
{
length = x;
breadth = y;
}
int calculate()
{
return(length*breadth);
}
}
public class Runtime
{
public static void main(String[] args)
{
Rectangle rectangle = new Rectangle();
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
rectangle.Displayvalues(x, y);
System.out.println(" Entered values are X="+x+"and =Y"+y);
int area = rectangle.calculate();
System.out.println(" area of a rectange is : " + area);
}
}
somebody help me...........
- 02-21-2013, 12:41 PM #2
Re: Please help me
You're running it without providing a parameter list, i.e. String[] args is empty.
EDIT Next time post with a meaningful title and wrap your code with [code] tagsMath problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 02-21-2013, 12:59 PM #3
Re: Please help me
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum - Learn Java Programming
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-21-2013, 01:04 PM #4
Member
- Join Date
- Feb 2013
- Posts
- 19
- Rep Power
- 0
Re: Please help me
Thanks for the rules
-
Re: Please help me
- 02-21-2013, 07:04 PM #6
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Please help me
Statement Integer.parseInt throws ioexception so u should use try and catch
try{
statements
}catch(Exception e){}
-
Re: Please help me
- Yes, it would be best to surround this type of parsing with a try/catch
- But you should avoid catching for the overly general Exception, but rather should catch for specific exceptions, here it would be NumberFormatException.
- No, this has nothing to with the original poster's original problem, that of an ArrayIndexOutofBounds exception since this is an exception which shouldn't be caught, since if it occurs it indicates a severe problem with program logic.
- And of course you were going to also recommend that if the OP does catch exceptions, he should never leave the catch block empty as it is in your example above, right?
- 02-22-2013, 04:53 AM #8
- 02-23-2013, 05:57 AM #9
Member
- Join Date
- Feb 2013
- Posts
- 19
- Rep Power
- 0
-
Re: Please help me
- 02-25-2013, 09:25 AM #11
Member
- Join Date
- Nov 2012
- Location
- India
- Posts
- 70
- Rep Power
- 0
Re: Please help me
your String[] args got null values.Do it display the error..
have you try pass some values to x and y it works...
I used scanner for put inputs and i got the area of the particular input it works well for me...
so you will try to put the intputs using scannerLast edited by tamilarasi; 02-25-2013 at 09:27 AM.
Regards
Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475
- 02-26-2013, 05:38 AM #12
Member
- Join Date
- Feb 2013
- Posts
- 19
- Rep Power
- 0


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks