我已經建立了一個應用程序的代碼是正確的。不過我越來越Android工作室IndexOutOfBoundsException錯誤
java.lang.IndexOutOfBoundsException的錯誤:無效指數7,大小爲7
每當我運行的應用程序。不知道有什麼問題
我檢查了很多解決方案沒有幫助我。
我的代碼是
public class Lecture extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lecture);
List<List<String>> arrayOfListsA= new ArrayList<List<String>>();
SharedPreferences sharedPreferences=getSharedPreferences("MyData",MODE_PRIVATE);
String username=sharedPreferences.getString("username","NA");
String password=sharedPreferences.getString("password","NA");
TextView av=(TextView)findViewById(R.id.tvavg);
double sub=0,subt=0,prd=0,sec=0,btch=0,day=0,date=0;
try {
arrayOfListsA = new HttpGetLecture().execute(username,password).get();
List<String> subject = new ArrayList<String>();
List<String> subjecttype = new ArrayList<String>();
List<String> period = new ArrayList<String>();
List<String> section = new ArrayList<String>();
List<String> batch = new ArrayList<String>();
List<String> day1 = new ArrayList<String>();
List<String> date1 = new ArrayList<String>();
GridView gridView=(GridView) findViewById(R.id.gridLect1);
subject = arrayOfListsA.get(1);
subjecttype = arrayOfListsA.get(2);
day1= arrayOfListsA.get(3);
period= arrayOfListsA.get(4);
date1= arrayOfListsA.get(5);
section= arrayOfListsA.get(6);
batch= arrayOfListsA.get(7);
/*for(int i=0;i<subject.size();i++) {
sub = sub + parseInt(subject.get(i));
} */
/* for(int j=0;j<subjecttype.size();j++){
subt=subt+ parseInt(subjecttype.get(j));
}
for(int k=0;k<period.size();k++){
prd=prd+ parseInt(period.get(k));
}
for(int l=0;l<section.size();l++){
sec=sec+ parseInt(section.get(l));
}
for(int m=0;m<batch.size();m++){
btch=btch+ parseInt(batch.get(m));
}
*/
//avg= (out/per) * 100;
//av.setText("Average Attendance :- "+ String.valueOf(avg)+" %");
gridView.setAdapter(new CustomAdapterLecture(this,subject,subjecttype,period,section,batch,day1,date1));
} catch (InterruptedException e) {
e.printStackTrace();
e.getMessage();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
大小開始7表示有效索引,從0-6 –
哪一部分錯誤不清?您正嘗試訪問超越邊界。你是否調試過並檢查了你進入arrayOfListsA的內容,看看發生了什麼?或者你只是從1開始而不是從0開始索引? –