My whileloop keeps on erroring while i'm trying to create an insert sort

I get this error when I try to run my code. Compiling works fine:
ArrayIndexOutOfBoundsException: 31
at ReadData.sort(ReadData.java:20)
at ReadDataApp.main(ReadDataApp.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
I'm trying to create an insertion sort within this method. If i comment the while loop out, it no longer errors, so the error will be somewhere in there.
public void sort(){
  for(int i=1; i < array.length; i++){
  int temp = array;
int j = array[i];
while(j > 0 && (array[j-1]) > temp){
array[j] = array[j-1];
j--;
}//end of while
temp = j;
}//end of for
}//end of sortThere are 20 items in the array.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

The error message tells you exactly what's going on: At line 20 of ReadData.java, you're trying to access the 32nd element (index 31) of an array that has 31 or fewer elements (indices 0..30 or less).
Put in some print statements so you can see where your code is not doing what you think it is.

Similar Messages

  • I got Class category is invalid error. while i am trying to create project by using pa_project_pub API trough backend

    Hi Everyone,
    Can you please help me.. how can i solve this problem.
    please find out the following code which was i written..
    DECLARE
      -- Variables needed to create task hierachy
      level1               NUMBER;
      level2               NUMBER;
      level3               NUMBER;
      a                    NUMBER;
      m                    NUMBER;
      parent_level1         VARCHAR2(30);
      parent_level2         VARCHAR2(30);
      parent_level3         VARCHAR2(30);
      number_of_tasks1      NUMBER;        -- number of tasks/levels
      number_of_tasks2      NUMBER;
      number_of_tasks3      NUMBER;
      number_of_tasks4      NUMBER;
      -- Variables needed for API standard parameters
      l_api_version_number  NUMBER := 1.0;
      l_commit                VARCHAR2(1) := 'F';
      l_return_status       VARCHAR2(1);
      l_init_msg_list       VARCHAR2(1) := 'F';
      l_msg_count           NUMBER;
      l_msg_index_out       NUMBER;
      l_msg_data            VARCHAR2(2000);
      l_data                VARCHAR2(2000);
      l_workflow_started    VARCHAR2(1) := 'Y';
      l_pm_product_code     VARCHAR2(10);
    -- Predefined Composit data types
      l_project_in          PA_PROJECT_PUB.PROJECT_IN_REC_TYPE;
      l_project_out         PA_PROJECT_PUB.PROJECT_OUT_REC_TYPE;
      l_key_members         PA_PROJECT_PUB.PROJECT_ROLE_TBL_TYPE;
      l_class_categories    PA_PROJECT_PUB.CLASS_CATEGORY_TBL_TYPE;
      l_tasks_in_rec        PA_PROJECT_PUB.TASK_IN_REC_TYPE;
      l_tasks_in            PA_PROJECT_PUB.TASK_IN_TBL_TYPE;
      l_tasks_out_rec       PA_PROJECT_PUB.TASK_OUT_REC_TYPE;
      l_tasks_out           PA_PROJECT_PUB.TASK_OUT_TBL_TYPE;
      l_cust_rec            PA_PROJECT_PUB.CUSTOMER_IN_REC_TYPE;
      l_cust_tbl            PA_PROJECT_PUB.CUSTOMER_TBL_TYPE;
      l_person_id           NUMBER;
      l_project_role_type   VARCHAR2(20);
      l_responsibility_id    NUMBER;
      l_user_id        NUMBER;
      v_ind            NUMBER;
      API_ERROR                EXCEPTION;
    BEGIN
    -- GET GLOBAL VALUES
      select user_id, responsibility_id
      into  l_user_id, l_responsibility_id
      from pa_user_resp_v
      where user_name = 'SATISH'                    -- substitute valid username
      and responsibility_name = '*PAC Projects Administrator';    -- substitute responsibility name
    dbms_output.put_line( 'initilaization');
    -- SET GLOBAL VALUES
      pa_interface_utils_pub.set_global_info(
        p_api_version_number    => 1.0,
        p_responsibility_id     => l_responsibility_id,
        p_user_id               => l_user_id, 
        p_msg_count             => l_msg_count,
        p_msg_data              => l_msg_data,
        p_return_status         => l_return_status);
      dbms_output.put_line( 'Assigning values');
    -- PRODUCT RELATED DATA
      l_pm_product_code := 'GMS';         -- can be user defined
    -- PRODUCT DATA (PROJECT_IN_REC_TYPE)
      l_project_in.created_from_project_id := 11759;--'1746';--'11759';  -- Project id from template
      l_project_in.project_name := 'TEST_VS_14052014';
      l_project_in.pm_project_reference := 'TEST_VS_14052014';
      l_project_in.description := 'CREATION OF PROJECT(VS)';
      l_project_in.project_status_code := 'APPROVED';
      l_project_in.carrying_out_organization_id := 652;--3274;    -- can default from template
      l_project_in.start_date := '01-JAN-2007'; -- can override default from template
      l_project_in.completion_date := '31-JAN-2010';       -- can override default from template
      l_project_in.actual_start_date := '01-JAN-2010';
      l_project_in.actual_finish_date := '31-JAN-2010';
      l_project_in.early_start_date := '01-JAN-2010';
      l_project_in.early_finish_date :='31-JAN-2010';
      l_project_in.late_start_date := '01-JAN-2010';
      l_project_in.late_finish_date :='31-JAN-2010';
    -- l_proj_in.process_mode := 'ONLINE';
    -- l_project_in.customer_id := 1001;
    --KEY MEMBERS DATA (PROJECT_ROLE_TBL_TYPE)
    -- can be defaulted from the Template, but not from a Project
      m := 1;
      l_person_id := 34;            -- need to get from Apps
      l_project_role_type := 'PROJECT MANAGER';
      l_key_members(m).person_id := 53;
      l_key_members(m).project_role_type := 'PROJECT MANAGER';
    -- l_class_categories(1).class_category := 'Engineering';
      --l_class_categories(1).class_code := 'Programs';
      --l_class_categories(2).class_category := 'Planned';
      --l_class_categories(2).class_code := 'Active';
      l_class_categories(3).class_category := 'Rank';
      l_class_categories(3).class_code := 'CUST';
    -- CUSTOMERS
      v_ind := 0;
      l_cust_rec.customer_id                    := 1001;
      l_cust_rec.project_relationship_code      := 'CLIENT'; --cus.project_relationship_code;
      l_cust_rec.Bill_To_Customer_id            := NULL; --cus.x_bill_customer_id;    
      l_cust_rec.contact_id                     := NULL;                   --  pa_interface_utils_pub.g_pa_miss_num;
      l_cust_rec.project_contact_type_code      := NULL;  --  pa_interface_utils_pub.g_pa_miss_char;
      l_cust_rec.customer_bill_split            := NULL; --nvl(cus.customer_bill_split, pa_interface_utils_pub.g_pa_miss_num);
      l_cust_rec.allow_inv_user_rate_type_flag  := NULL; --nvl(cus.allow_inv_user_rate_type_flag, pa_interface_utils_pub.g_pa_miss_char);
      l_cust_rec.inv_rate_date                  := NULL; --nvl(cus.inv_rate_date, pa_interface_utils_pub.g_pa_miss_date);
      l_cust_rec.inv_rate_type                  := NULL; --nvl(cus.inv_rate_type, pa_interface_utils_pub.g_pa_miss_char);
      l_cust_rec.inv_currency_code              := NULL; --nvl(cus.inv_currency_code, pa_interface_utils_pub.g_pa_miss_char);
      l_cust_rec.inv_exchange_rate              := NULL; --nvl(cus.inv_exchange_rate, pa_interface_utils_pub.g_pa_miss_num);
      l_cust_rec.bill_another_project_flag      := 'Y'; --nvl(cus.bill_another_project_flag, pa_interface_utils_pub.g_pa_miss_char);
      l_cust_rec.RECEIVER_TASK_ID               := 35078;
      v_ind  :=  v_ind  +  1;
      l_cust_tbl   (v_ind)  :=  l_cust_rec;
    --CLASS CATEGORIES DATA (CLASS_CATEGORY_TBL_TYPE)
    --  l_class_categories(1).class_category := 'Product'; --value from template
    --  l_class_categories(1).class_code := 'Product 1';
    --TASKS DATA
      --Set the number of tasks for every level (there are 4 levels)
      number_of_tasks1 := 1;
      number_of_tasks2 := 2;
      number_of_tasks3 := 0;
      number_of_tasks4 := 0;
    -- This is just a set of looping structures to create the tasks and sub-tasks
    -- If it is difficult to understand, then feel free to create them individually.
      a := 0;
      for level1 in 1..number_of_tasks1 loop
        a := a + 1;
        l_tasks_in_rec.pm_task_reference := level1 || '.' || '0';
        l_tasks_in_rec.task_name := 'Top Level ' || level1 || '.' || '0';
        l_tasks_in_rec.pm_parent_task_reference := '';
        l_tasks_in_rec.task_start_date := '01-JAN-2010';
        l_tasks_in_rec.task_completion_date := '31-JAN-2010';
        l_tasks_in_rec.actual_start_date := '01-JAN-2010';
        l_tasks_in_rec.actual_finish_date :='31-JAN-2010';
        l_tasks_in_rec.early_start_date := '01-JAN-2010';
        l_tasks_in_rec.early_finish_date :='31-JAN-2010';
        l_tasks_in_rec.late_start_date := '01-JAN-2010';
        l_tasks_in_rec.late_finish_date :='31-JAN-2010';
        l_tasks_in_rec.receive_project_invoice_flag := 'Y';
        l_tasks_in(a) := l_tasks_in_rec;
        parent_level1 := level1 || '.' || '0';
        for level2 in 1..number_of_tasks2 loop
          a := a + 1;
          l_tasks_in_rec.pm_task_reference := level1 || '.' || level2;
          l_tasks_in_rec.task_name := '2 Level ' || level1 || '.' || level2;
          l_tasks_in_rec.pm_parent_task_reference := parent_level1;
          l_tasks_in(a) := l_tasks_in_rec;
          parent_level2 := level1 || '.' || level2;
        end loop;
      end loop;
    --INIT_CREATE_PROJECT
      pa_project_pub.init_project;
    --CREATE_PROJECT
      pa_project_pub.create_project(
        l_api_version_number,
        p_commit            => l_commit,
        p_init_msg_list     => l_init_msg_list,
        p_msg_count         => l_msg_count,
        p_msg_data          => l_msg_data,
        p_return_status     => l_return_status,
        p_workflow_started  => l_workflow_started,
        p_pm_product_code   => l_pm_product_code,
        p_project_in        => l_project_in,
        p_project_out       => l_project_out,
        p_key_members       => l_key_members,
        p_class_categories  => l_class_categories,
        p_tasks_in          => l_tasks_in,
        p_tasks_out         => l_tasks_out,
        p_customers_in      => l_cust_tbl);
    -- Check for errors
      if l_return_status != 'S'
      then
        raise API_ERROR;
      end if;
      dbms_output.put_line('New Project Id: ' || l_project_out.pa_project_id);
      dbms_output.put_line('New Project Number: ' || l_project_out.pa_project_number);
      Commit;
    --HANDLE EXCEPTIONS
    -- Get the error message that were returned if it did not complete sucessfully
      EXCEPTION
      When API_ERROR then
        if l_msg_count >= 1
        then
          for i in 1..l_msg_count loop
            pa_interface_utils_pub.get_messages(
            p_msg_data      => l_msg_data,
            p_encoded       => 'F',
            p_data          => l_data,
            p_msg_count     => l_msg_count,
            p_msg_index     => l_msg_count,    -- Added in 11i.PA.I
            p_msg_index_out => l_msg_index_out);
            dbms_output.put_line('error message: ' || l_data);
          end loop;
          rollback;
        end if;
      When OTHERS then
        if l_msg_count >= 1
          then
          for i in 1..l_msg_count loop
            pa_interface_utils_pub.get_messages(
            p_msg_count     => l_msg_count,
            p_encoded    => 'F',
            p_msg_data     => l_msg_data,
            p_data         => l_data,
            p_msg_index     => l_msg_count,    -- Added in 11i.PA.I
            p_msg_index_out => l_msg_index_out);
            dbms_output.put_line('error message: ' || l_data);
          end loop;
          rollback;
        end if;
    END;
    ERROR:=
    initilaization
    Assigning values
    debug message -->: Start..
    debug message -->: 1
    debug message -->: 2
    debug message -->: 3
    debug message -->: 4
    debug message -->: 5
    debug message -->: 6
    debug message -->: 7
    debug message -->: 8
    debug message -->: 9
    debug message -->: 10
    debug message -->: 11
    debug message -->: 12
    debug message -->: 13
    debug message -->: 14
    debug message -->: 15
    debug message -->: 16
    debug message -->: 17
    debug message -->: 18
    debug message -->: 19
    debug message -->: 20
    debug message -->: 21
    debug message -->: 22
    debug message -->: 23
    debug message -->: 25
    debug message -->: 26
    debug message -->: 26-I
    debug message -->: 26-II
    debug message -->: 26-I
    debug message -->: 26-II
    debug message -->: 26-I
    debug message -->: 26-II
    debug message -->: 26-I
    debug message -->: 26-II
    debug message -->: 26-Vi
    debug message -->: 26-I
    debug message -->: 26-II
    debug message -->: 26-VII
    debug message -->: 27
    debug message -->: 28
    debug message -->: 30
    error message: Project: 'TEST_VS_14052014'
    The class category is invalid.

    Please see if (PA_PROJECT_PUB.create_project Errors - The Class Category Is Invalid (Doc ID 1323904.1)) helps.
    Thanks,
    Hussein

  • Trying to re install PSE 11 and keep getting error while installing Shared Technologies

    Trying to re install PSE 11 and keep getting error while installing Shared Technologies

    Try this link first:
    <Install rollback and Shared Technologies | Windows>
    It is for the Windows system but if you are using Apple MAC then you'll have to wait until Barbara is here later today.

  • HT201210 i keep getting errors while i try to restore my iphone. can you please help?

    Hello. I wanted to restore my iphone but i keep getting errors while i'm at it. 1015 and some others. It is still in recovery mode and i cannot seem to solve anything. Can you please help? I have an iphone 3G which used to work on iOS 4.2.1. Thanks

    ERROR 1015...
    This Error Code is indicative of the Device being jailbroken / Hacked...
    Unauthorized modification of iOS  >  http://support.apple.com/kb/HT3743
    Sorry... But...
    The discussion of Jailbroken Devices is against the Terms of Use of this Forum.
    You will need to look elsewhere.

  • I keep getting error code 3212 when trying to connect to home sharing.. i am connected to the internet

    i keep getting error code 3212 when trying to connect to home sharing.. i am connected to the internet

    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • Keep getting error code 2048 when trying to open wmv files, says realplayer cannot open with the installed version of Quicktime, any suggestions?

    Keep getting error code 2048 when trying to open wmv files, says realplayer cannot open with the installed version of Quicktime, any suggestions?

    wmv is a Windows Media format.  I don't know why Realplayer is coming into it since that deals primarily with Real format files and maybe a few generic formats.
    You need
    Free Flip4mac QuickTime player components - http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx
    After installation a new Flip4Mac pane will appear in System Preferences.  Make sure you set the boxes to ensure that it will play WMV files in Quicktime.
    or play the files with VLC
    VLC media player - http://www.videolan.org/vlc/ - general media player that plays just about anything.
    While you're at it you might install:
    Perian codecs for Quicktime - http://www.perian.org - plugins to add functionality to Quicktime for playing additional audio and video formats
    Quicktime audio problems, Perian, VLC - http://discussions.apple.com/message.jspa?messageID=9013669 - read note about uninstalling prior DIVX support before installing Perian.
    Perian doen't do WMV but it's handy to get many things to play in Quicktime.
    Note, if these are protected WMV, nothing on a Mac will play those (unless you also have Windows installed).

  • Get error while invoking a page with "create"

    I get this error while invoking a page with "create". Also please any one tell me where is the log file is place to see the full story.
    ]] Root cause of ServletException.
    javax.el.PropertyNotFoundException: Target Unreachable, 'Comments' returned null
         at com.sun.el.parser.AstValue.getTarget(AstValue.java:88)
         at com.sun.el.parser.AstValue.isReadOnly(AstValue.java:126)
         at com.sun.el.ValueExpressionImpl.isReadOnly(ValueExpressionImpl.java:230)
         at oracle.adfinternal.view.faces.renderkit.rich.EditableValueRenderer.getReadOnly(EditableValueRenderer.java:400)
         at oracle.adfinternal.view.faces.renderkit.rich.FormElementRenderer.renderAsElement(FormElementRenderer.java:199)
         Truncated. see log file for complete stacktrace
    If i use a "create button then it does not throw error.
    Please help.

    When you are invoking your page, does your view object has an empty row where data can go and presist?
    Create a an empty row in your view object(vo.createRow()) , or use create operation from data control palette.
    You can set the log in Tools->Preferences-->Environment-->Log.
    Regards,
    Vikram

  • HT4061 3GS stuck on connect to iTunes screen and keep getting error 29 at restore tried 5 different batteries all with different apn numbers what apn should my batterie have

    Keep getting error 29 I have tried 5 batteries now all with different apn numbers which is the correct batterie to use in my 3GS

    Error 20, 21, 23, 26, 28, 29, 34, 37
    These errors typically occur when security software interferes with the restore and update process. FollowTroubleshooting security software issues to resolve this issue. In rare cases, these errors may be a hardware issue. If the errors persist on another computer, the device may need service

  • HT1918 why do I keep getting error code 5002 when trying to make a purchase? Has been almost a week now!

      Why do I keep getting Error Code 5002 when trying to make a purchase from the Itunes store? I am using Vista Home edition> havent had any problems before. This has been going on for a week.

    This alert is often the result of an issue with verifying your billing.
    Quit iTunes.
    Open iTunes.
    Test the issue.
    If it persists, sign in to store.apple.com using your iTunes account
    Click on Change account information
    Modify or remove your credit card information.
    Click Continue.
    Test the issue.

  • I keep getting error code 3131 when trying to publish a ping playlist -- help!!!

    I keep getting error code 3131 when trying to publish a ping playlist -- help!!!

    Same problem. I make playlists on Ping so the listeners of my podcast can easily download the songs I talk about. But for **** near 2 weeks now I can't edit a playlist or add a new one. When are they gonna fix this?

  • I keep getting error message U44M1P2003 when trying to update photo shop elements 12

    I keep getting error message U44M1P2003 when trying to update photo shop elements 12 can any one help an OAP Luddite?

    See if that can help:
    Update 12.1 installation errors | Photoshop Elements, Premiere Elements

  • Keep getting error message 4310 when trying to burn music onto CD? How can I fix this for free?

    Keep getting error message 4310 when trying to burn music from playlist onto CD. How can I fix this for free?

    You can use the email form here >  Apple - Support - iTunes Store - Contact Us
    iTunes Store & Mac App Store: About your Apple ID and password

  • TS3694 keep geting error code 1015 when trying to update my iphone 3gs any tips to sort it out

    keep geting error code 1015 when trying to update my iphone 3gs any tips to sort it out

    https://discussions.apple.com/message/19425288#19425288
    https://discussions.apple.com/message/18882000#18882000
    https://discussions.apple.com/message/18526759#18526759
    http://support.apple.com/kb/TS3694?viewlocale=en_US
    Errors related to downgrading iOS
    The required resource cannot be found: This alert message occurs when your device has a newer version of iOS than what is available in iTunes. When troubleshooting a device that presents this alert message, go toSettings > General > About and check the version of iOS on the device. If it is newer than the latest released iOS version, the device may have a prerelease developer version of iOS installed. Installing an older version of iOS over a newer version is not supported.
    Error 1015: This error is typically caused by attempts to downgrade the iPhone, iPad, or iPod touch's software. This can occur when you attempt to restore using an older .ipsw file. Downgrading to a previous version is not supported. To resolve this issue, attempt to restore with the latest iPhone, iPad, or iPod touch software available from Apple. This error can also occur when an unauthorized modification of the iOS has occurred and you are now trying to restore to an authorized, default state.
    There is not much you can do, sorry 

  • Why does my iPhoto keep quitting while i'm trying to create a calendar?

    Why does my iPhoto keep quitting while i'm trying to create a calendar

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Step 1
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left. If you don't see that menu, select
    View ▹ Show Log List
    from the menu bar.
    Enter the name of the crashed application or process in the Filter text field. Select the messages from the time of the last crash, if any. Copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Anonymize before posting.
    Step 2
    In the Console window, look under User Diagnostic Reports for crash reports related to the crashed process. The report name starts with the name of the process, and ends with ".crash". Select the most recent report and post the entire contents — again, the text, not a screenshot. In the interest of privacy, I suggest that, before posting, you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header of the report, if it’s present (it may not be.) Please don’t post other kinds of diagnostic report — they're very long and not helpful.

  • How come I keep getting errror message -50n when trying to create slow motion footage?

    How comme I can not slow motion a section of video keep getting error message -50?

    Tried that still coming up with error message: -50? set up a troble call to apple thanks...

Maybe you are looking for

  • Error while creating an Invoice in SRM

    Hi All, We are on SRM 7.0, ECC 6.0 (Classic scenario). My SC has been approved and a PO has been created in ECC, I have also created a confirmation against this from SRM which resulted in a GR being created against the PO in ECC. Now when I am creati

  • How to print in a local printer

    Hi, i was wondering if is there an option to show the button that allow the user to select the local printer to print the report generated by de JSP viewer. I only can print the report via PDF and that's not a good solution for my project. Can you he

  • UNAVAILABLE CALLS DRIVING ME INSANE

    Why does the anonymous call block not include calls that show as UNAVAILABLE????  I have recieved 5 calls from UNAVAILABLE in the last 3 hours.  The first 3 I did not pick up.  The last 2 I did, with nobody on the other end, just silence and then dis

  • Disable video card driver and use generic VGA

    Is there a way to just use a generic VGA driver for the macbook pro? I'm having problems with my macbook pro regarding display issues and crashing. It works fine in safe mode, which disables the ati video driver. Is there a way to have the macbook pr

  • To disable one field of standard sap screen.

    Hi, I want to disable one field of standard SAP screen for example tran code : MD61 Field : Version. Can Anybody suggest me with simple coding. thanks naresh