Results 1 to 12 of 12
Like Tree2Likes
  • 1 Post By DarrylBurke
  • 1 Post By Fubarable

Thread: Please help me

  1. #1
    sathishvegeta is offline Member
    Join Date
    Feb 2013
    Posts
    20
    Rep Power
    0

    Default 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...........

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default 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] tags
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Please help me

    PhHein likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    sathishvegeta is offline Member
    Join Date
    Feb 2013
    Posts
    20
    Rep Power
    0

    Default Re: Please help me

    Thanks for the rules

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Please help me

    Quote Originally Posted by sathishvegeta View Post
    Thanks for the rules
    Rules that will help others be able to better help you, so yes, you're quite welcome.
    DarrylBurke likes this.

  6. #6
    seena is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: Please help me

    Statement Integer.parseInt throws ioexception so u should use try and catch
    try{
    statements
    }catch(Exception e){}

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Please help me

    Quote Originally Posted by seena View Post
    Statement Integer.parseInt throws ioexception so u should use try and catch
    try{
    statements
    }catch(Exception e){}
    • 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?

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Please help me

    Quote Originally Posted by seena View Post
    Statement Integer.parseInt throws ioexception
    No it doesn't.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    sathishvegeta is offline Member
    Join Date
    Feb 2013
    Posts
    20
    Rep Power
    0

    Default Re: Please help me

    Quote Originally Posted by seena View Post
    Statement Integer.parseInt throws ioexception so u should use try and catch
    try{
    statements
    }catch(Exception e){}
    Even if i use try Catch i cant enter the input at runtime.. pls guide me briefly

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Please help me

    Quote Originally Posted by sathishvegeta View Post
    Even if i use try Catch i cant enter the input at runtime.. pls guide me briefly
    We can best guide if we know what you're doing wrong. Please show your attempt at using this including code posted with code tags, show any errors or exceptions that this code causes, and explain your most current problems with the code.

  11. #11
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default 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 scanner
    Last edited by tamilarasi; 02-25-2013 at 09:27 AM.
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

  12. #12
    sathishvegeta is offline Member
    Join Date
    Feb 2013
    Posts
    20
    Rep Power
    0

    Default Re: Please help me

    Quote Originally Posted by tamilarasi View Post
    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 scanner
    yep... now i got it and it worked thanks for ur info....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •