我想将多个选择列表视图保存到MySQL数据库,但LogCat给出错误
" java.lang.IndexOutOfBoundsException" ..
这是我的代码
SparseBooleanArray checked = kuliah.getCheckedItemPositions();
ArrayList<String> selectedItems = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems.add(adapter.getItem(position));
}
ArrayList<String> selectedItems1 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems1.add(adapter1.getItem(position));
}
ArrayList<String> selectedItems2 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems2.add(adapter2.getItem(position));
}
ArrayList<String> selectedItems3 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems3.add(adapter3.getItem(position));
}
ArrayList<String> selectedItems4 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems4.add(adapter1111.getItem(position));
}
ArrayList<String> selectedItems5 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems5.add(adapter6.getItem(position));
}
ArrayList<String> selectedItems6 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems6.add(adapter7.getItem(position));
}
ArrayList<String> selectedItems7 = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems7.add(adapter8.getItem(position));
}
String[] outputStrArr = new String[selectedItems.size()];
for (int i = 0; i < selectedItems.size(); i++) {
outputStrArr[i] = selectedItems.get(i);
}
String[] outputStrArr1 = new String[selectedItems1.size()];
for (int i = 0; i < selectedItems1.size(); i++) {
outputStrArr1[i] = selectedItems1.get(i);
}
String[] outputStrArr2 = new String[selectedItems2.size()];
for (int i = 0; i < selectedItems2.size(); i++) {
outputStrArr2[i] = selectedItems2.get(i);
}
String[] outputStrArr3 = new String[selectedItems3.size()];
for (int i = 0; i < selectedItems3.size(); i++) {
outputStrArr3[i] = selectedItems3.get(i);
}
String[] outputStrArr4 = new String[selectedItems4.size()];
for (int i = 0; i < selectedItems4.size(); i++) {
outputStrArr4[i] = selectedItems4.get(i);
}
String[] outputStrArr5 = new String[selectedItems5.size()];
for (int i = 0; i < selectedItems5.size(); i++) {
outputStrArr5[i] = selectedItems5.get(i);
}
String[] outputStrArr6 = new String[selectedItems6.size()];
for (int i = 0; i < selectedItems6.size(); i++) {
outputStrArr6[i] = selectedItems6.get(i);
}
String[] outputStrArr7 = new String[selectedItems7.size()];
for (int i = 0; i < selectedItems7.size(); i++) {
outputStrArr7[i] = selectedItems7.get(i);
}
convertarraytostring(outputStrArr);
convertarraytostring(outputStrArr1);
convertarraytostring(outputStrArr2);
convertarraytostring(outputStrArr3);
convertarraytostring(outputStrArr4);
convertarraytostring(outputStrArr5);
convertarraytostring(outputStrArr6);
convertarraytostring(outputStrArr7);
int TIMEOUT_MILISEC = 10000;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILISEC);
HttpClient client = new DefaultHttpClient(httpParams);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("NIM",getIntent().getStringExtra("NIM")));
nameValuePairs.add(new BasicNameValuePair("Matakuliah_ID",matkulID.toString()));
nameValuePairs.add(new BasicNameValuePair("kuliah1",convertarraytostring(outputStrArr)));
nameValuePairs.add(new BasicNameValuePair("kuliah2",convertarraytostring(outputStrArr1)));
nameValuePairs.add(new BasicNameValuePair("kuliah3",convertarraytostring(outputStrArr2)));
nameValuePairs.add(new BasicNameValuePair("kuliah4",convertarraytostring(outputStrArr3)));
nameValuePairs.add(new BasicNameValuePair("kuliah5",convertarraytostring(outputStrArr4)));
nameValuePairs.add(new BasicNameValuePair("kuliah6",convertarraytostring(outputStrArr5)));
nameValuePairs.add(new BasicNameValuePair("kuliah7",convertarraytostring(outputStrArr6)));
nameValuePairs.add(new BasicNameValuePair("kuliah8",convertarraytostring(outputStrArr7)));
我认为错误消息来自数组列表..感谢您的帮助..
这是LogCat
08-28 16:15:07.704: E/AndroidRuntime(1070): FATAL EXCEPTION: main
08-28 16:15:07.704: E/AndroidRuntime(1070): java.lang.IndexOutOfBoundsException
08-28 16:15:07.704: E/AndroidRuntime(1070): at java.util.Arrays$ArrayList.get(Arrays.java:75)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
08-28 16:15:07.704: E/AndroidRuntime(1070): at com.coba.wali$1.onClick(wali.java:110)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.view.View.performClick(View.java:2485)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.view.View$PerformClick.run(View.java:9080)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.os.Handler.handleCallback(Handler.java:587)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.os.Handler.dispatchMessage(Handler.java:92)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.os.Looper.loop(Looper.java:130)
08-28 16:15:07.704: E/AndroidRuntime(1070): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-28 16:15:07.704: E/AndroidRuntime(1070): at java.lang.reflect.Method.invokeNative(Native Method)
08-28 16:15:07.704: E/AndroidRuntime(1070): at java.lang.reflect.Method.invoke(Method.java:507)
08-28 16:15:07.704: E/AndroidRuntime(1070): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-28 16:15:07.704: E/AndroidRuntime(1070): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-28 16:15:07.704: E/AndroidRuntime(1070): at dalvik.system.NativeStart.main(Native Method)