求助:报错java.lang.ArrayIndexOutOfBoundsException.length=1;index=1
package com.example.parkingmanagement1;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class AddCarTrackActivity extends Activity {
ParkingLotDbHelper parkingLotdbHelper;
Spinner pl_carTrack_parkingLotSel;
EditText pl_carTrack_code,pl_carTrack_remarks;
EditText pl_carTrack_gpsX1,pl_carTrack_gpsY1,pl_carTrack_gpsX2,pl_carTrack_gpsY2;
EditText pl_carTrack_gpsX3,pl_carTrack_gpsY3,pl_carTrack_gpsX4,pl_carTrack_gpsY4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addcartrack);
parkingLotdbHelper = new ParkingLotDbHelper(this, "ParkingMangement.db3", 1);
pl_carTrack_parkingLotSel = (Spinner)findViewById(R.id.pl_carTrack_parkingLotSel);
pl_carTrack_code = (EditText)findViewById(R.id.pl_carTrack_code);
pl_carTrack_remarks = (EditText)findViewById(R.id.pl_carTrack_remarks);
pl_carTrack_gpsX1 = (EditText)findViewById(R.id.pl_carTrack_gpsX1);
pl_carTrack_gpsY1 = (EditText)findViewById(R.id.pl_carTrack_gpsY1);
pl_carTrack_gpsX2 = (EditText)findViewById(R.id.pl_carTrack_gpsX2);
pl_carTrack_gpsY2 = (EditText)findViewById(R.id.pl_carTrack_gpsY2);
pl_carTrack_gpsX3 = (EditText)findViewById(R.id.pl_carTrack_gpsX3);
pl_carTrack_gpsY3 = (EditText)findViewById(R.id.pl_carTrack_gpsY3);
pl_carTrack_gpsX4 = (EditText)findViewById(R.id.pl_carTrack_gpsX4);
pl_carTrack_gpsY4 = (EditText)findViewById(R.id.pl_carTrack_gpsY4);
makeAapterList();
}
private void makeAapterList()
{
Cursor cursor;
String [] arrForAdaptor = {null};
cursor = parkingLotdbHelper.getReadableDatabase().rawQuery("select * from parkingLot", null);
int i = 0;
while (cursor.moveToNext())
{
// 将结果集中的数据存入ArrayList中
arrForAdaptor[i++] = cursor.getString(1) + "(" + cursor.getString(4) + ")";
//result.add(map);
}
//实现pl_carTrack_parkingLotSel单选功能
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
arrForAdaptor);
pl_carTrack_parkingLotSel.setAdapter(adapter);
}
public void submit(View source)
{
String temp_code = (pl_carTrack_parkingLotSel.getSelectedItem()).toString();
String pl_code = temp_code.substring(temp_code.indexOf('(') + 1, temp_code.indexOf(')'));
String remarks = pl_carTrack_remarks.getText().toString();
String code = pl_carTrack_code.getText().toString();
String gpsX1 = pl_carTrack_gpsX1.getText().toString();
String gpsY1 = pl_carTrack_gpsY1.getText().toString();
String gpsX2 = pl_carTrack_gpsX2.getText().toString();
String gpsY2 = pl_carTrack_gpsY2.getText().toString();
String gpsX3 = pl_carTrack_gpsX3.getText().toString();
String gpsY3 = pl_carTrack_gpsY3.getText().toString();
String gpsX4 = pl_carTrack_gpsX4.getText().toString();
String gpsY4 = pl_carTrack_gpsY4.getText().toString();
insertData(parkingLotdbHelper.getReadableDatabase(),pl_code, remarks,code,gpsX1,gpsY1,gpsX2,gpsY2,gpsX3,gpsY3,gpsX4,gpsY4);
finish();
}
private void insertData(SQLiteDatabase db,String pl_code, String remarks,String code,
String gpsX1,String gpsY1,String gpsX2,String gpsY2,String gpsX3,String gpsY3,String gpsX4,String gpsY4)
{
String sql = "insert into carTrack values(null,?,?,?,?,?,?,?,?,?,?,?)";
String[] valueList = new String[] {pl_code, remarks,code,gpsX1,gpsY1,gpsX2,gpsY2,gpsX3,gpsY3,gpsX4,gpsY4};
db.execSQL(sql,valueList);
Toast.makeText(this, "Success", 8000).show();
}
public void cancel(View source)
{
finish();
}
@Override
public void onDestroy()
{
super.onDestroy();
if (null != parkingLotdbHelper)
{
parkingLotdbHelper.close();
}