Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Exception at main...

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Exception at main...

    I'm pretty new to Java Programming, and I'm trying out different ways to make a calculator with the JOptionPane, but I can't get this to work... I'm pretty sure it's something simple.. Here's what I have:


    [Java] Calculator V3 - Pastebin.com


    And it outprints:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
    	at Multiply.Process(Multiply.java:18)
    	at Calculator.main(Calculator.java:17)


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Exception at main...

    The length of your Object array = 2;
    The element you're trying to access using 'options[3]' = 4.

    You can't use what doesn't exist.

     Object[] options = {"Integers", "Doubles"};
            int in = JOptionPane.showOptionDialog(null, "What sort of multiplying will you be doing?",
                    "Calculator Version 3",
                    JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    options,
                    options[3]);

    In future, post all code here using code tags, and ask proper questions.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Exception at main...

    Oh derp...

    And um, what do you mean by "ask proper questions"?

    Are you telling me to rephrase everything into a question next time?

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Exception at main...

    Yeah. Saying how new to Java you are and then ending with "here's what I have" is very lazy.
    If this was a more complicated issue no one would have a clue what you were on about.

    Next time, detail the problems you're receiving, what you were doing when you received the problem and all the error codes with the code which the errors were referring to.
    Additionally, always post the code on these forums, but only the relevant ones, we don't want to have to read through lines and lines of code which is of little importance.

    ! Also; when you post here in the future, don't remove your code once you've been helped. It goes against the community spirit as well as diminishing the chances for other people with a similar issue to resolve their problems without the need of creating additional threads.
    Last edited by newbie; March 15th, 2012 at 07:31 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  5. The Following User Says Thank You to newbie For This Useful Post:

    Paetilium (March 15th, 2012)

  6. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Exception at main...

    I see. I didn't mean to convey that type of image, however I'm starting to make it a habit to remove older versions of things I'm working on but I understand completely and I'm sorry. Next time I'll be sure to keep it up. And I didn't mean to be such a "cliché" >.<. I'll keep all of that in mind the next time I've got a problem.

Similar Threads

  1. exception in thread main java.lang.Nullpointerexception
    By westandeast in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 6th, 2011, 09:08 AM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Replies: 2
    Last Post: March 26th, 2010, 12:22 PM
  4. Please help! Exception in thread "main" java.lang.NullPointerException
    By Arutha2321 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 18th, 2009, 02:25 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 12:54 PM