java - Android league app keeps crashing -


need bit of help, creating app sends results of ten team name, games won , drawn calculation work out total points supposed display them after continue button clicked app crashes. heres code guides on whats went wrong many thanks

package com.example.leaguetest;  import android.app.activity; import android.os.bundle; import android.view.menu; import android.widget.textview;   public class display extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_display);      //get the bundle inside intent     bundle m = this.getintent().getextras();      string [] teamname = m.getstringarray("teamname");     string[] swin = m.getstringarray("win");     string[] sdraw =  m.getstringarray("draw");     int [] win = new int[10];     int [] draw = new int [10];       // convert string integer win     win[1] = integer.parseint(swin[1]);     win[2] = integer.parseint(swin[2]);     win[3] = integer.parseint(swin[3]);     win[4] = integer.parseint(swin[4]);     win[5] = integer.parseint(swin[5]);     win[6] = integer.parseint(swin[6]);     win[7] = integer.parseint(swin[7]);     win[9] = integer.parseint(swin[8]);     win[9] = integer.parseint(swin[9]);     win[10] = integer.parseint(swin[10]);     // convert string integer draw     draw[1] = integer.parseint(sdraw[1]);     draw[2] = integer.parseint(sdraw[2]);     draw[3] = integer.parseint(sdraw[3]);     draw[4] = integer.parseint(sdraw[4]);     draw[5] = integer.parseint(sdraw[5]);     draw[6] = integer.parseint(sdraw[6]);     draw[7] = integer.parseint(sdraw[7]);     draw[8] = integer.parseint(sdraw[8]);     draw[9] = integer.parseint(sdraw[9]);     draw[10] = integer.parseint(sdraw[10]);       //calculation      int result1 = (win[1]* 3)+draw[1];        textview result1t=(textview)findviewbyid(r.id.textview1);     result1t.settext(teamname[1] );               textview result2t=(textview)findviewbyid(r.id.textview2);     result2t.settext( result1);           }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.display, menu);     return true; }     } 

package com.example.leaguetest;  import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.view; import android.widget.edittext;   public class mainactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; }    //global variables string [] teamname = new string[9]; string [] win = new string[9]; string [] draw = new string [9]; int counter = 0;  public void save(view view) {      edittext team =(edittext)findviewbyid(r.id.editteamname);     edittext wing=(edittext)findviewbyid(r.id.editwin);     edittext drawg=(edittext)findviewbyid(r.id.editdraw);     edittext lossg=(edittext)findviewbyid(r.id.editloss);       //if teams not greater 10     if(counter < 9){          //putting inputs array         teamname[counter] = team.gettext().tostring();         win[counter]= wing.gettext().tostring();         draw[counter]= drawg.gettext().tostring();            counter ++;     }      //reset text boxes          team.settext("");         wing.settext("");         drawg.settext("");         lossg.settext("");     }//end if    public void continue(view view) {      //bundle     bundle mybundle =  new bundle();     intent myintent = new intent(this, display.class);      //put arrays bundle     mybundle.putstringarray("name", teamname);     mybundle.putstringarray("win", win);     mybundle.putstringarray("draw", draw);      //put bundle intent     myintent.putextras(mybundle);      //start activity defined in intent     startactivity(myintent);  }//end savenamegrade 

}

java array indices 0 based.

this line of code:

int [] win = new int[10]; 

delcares array of 10 items. these items have index range 0..9.

this line of code:

win[10] = integer.parseint(swin[10]); 

attempts assign value out of range array. suspect accessing swin[10] crashes before that.

i think want this:

for (int index = 0; index < (swin.length) && (index < 10); index++) {    win[index] = integer.parseint(swin[index]);    } 

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 -