arrays - How to resolve Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2? -


can me solving type of error

exception in thread "main" java.lang.arrayindexoutofboundsexception: 2

i searching data in linked list when want insert data array, turn this:

matric | nama | sem | cc | ch | fm   32255 | izzat | 1 | ccs2 | 3 | 45.0         |      | 2 | ccs3 | 3 | 56.0   32345 | khai] | 3 | ccs4 | 3 | 45.0         |      | 2 | ccs5 | 3 | 2.0   32246 | fifi | 1 | cc1 | 3 | 60.0         |      | 1 | ccs3 | 4 | 34.0   34567 | dudu | 2 | ccs2 | 2 | 24.0         |      | 2 | ccs4 | 6 | 79.0  first-->34567-->32246-->32345-->32255-->null   first-->6-->2-->4-->3-->3-->3-->3-->3-->null   first-->2-->2-->1-->1-->2-->3-->2-->1-->null   first-->dudu-->fifi-->khai]-->izzat-->null   first-->ccs4-->ccs2-->ccs3-->cc1-->ccs5-->ccs4-->ccs3-->ccs2-->null   first-->79.0-->24.0-->34.0-->60.0-->2.0-->45.0-->56.0-->45.0-->null   42insert matric= 032345   exception in thread "main" java.lang.arrayindexoutofboundsexception: 2   2   khai]   2   3       @ inputoutput.linkedlist.getcc(linkedlist.java:141)       @ inputoutput.baca.getcc(baca.java:84)       @ inputoutput.inputoutput.main(inputoutput.java:75)    java result: 1    build successful (total time: 7 seconds)   

the code:

string[] getcc(int mat,int sub) {     listobject2 current = first2;             int count=0;             string b[]=new string[2] ;//2 subject number==sub              int x=0;              while (current!=null ) {                          if(count==((mat*sub)+x) && ((mat*sub)+0)<((mat*sub)+x)<<((mat*sub)+sub)){                            b[x]=current.data2;                              x++;                          }         current=current.next;                     count++;             }     return b; } 

but input if search last data in linked list 032255

this output:

 matric | nama | sem | cc | ch | fm    32255 | izzat | 1 | ccs2 | 3 | 45.0          |      | 2 | ccs3 | 3 | 56.0    32345 | khai] | 3 | ccs4 | 3 | 45.0          |      | 2 | ccs5 | 3 | 2.0    32246 | fifi | 1 | cc1 | 3 | 60.0          |      | 1 | ccs3 | 4 | 34.0    34567 | dudu | 2 | ccs2 | 2 | 24.0          |      | 2 | ccs4 | 6 | 79.0      first-->34567-->32246-->32345-->32255-->null      first-->6-->2-->4-->3-->3-->3-->3-->3-->null      first-->2-->2-->1-->1-->2-->3-->2-->1-->null      first-->dudu-->fifi-->khai]-->izzat-->null      first-->ccs4-->ccs2-->ccs3-->cc1-->ccs5-->ccs4-->ccs3-->ccs2-->null      first-->79.0-->24.0-->34.0-->60.0-->2.0-->45.0-->56.0-->45.0-->null      42insert matric= 032255      3      izzat      2      1      ccs3//the data want search      ccs2// 

you're going if statement more twice while walking list. if that, you'll go past bounds of b array (which can hold 2 values). should use arraylist instead can add many items need.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -