关于数组越界

时间:2022-01-17 02:28:44
今天写的项目运行时崩了,报的错是数组越界: 关于数组越界
但是我不知道怎么会没有获取到数值,求解,代码如下:
public class GetMsgFanCActivity extends BaseActivity {
    private Context mContext;
    private View mBaseView;
    private ListView mSettingListView;
    private SharedPreferences mSp;
    private List<String> itemString = new ArrayList<>();
    private String TestStr;
    private TextView tv_layout_title;
    private Button btn_title_layout_left;
    private List<ArrayList<String>>mArrayList=new ArrayList<>();
    private  List<GetMsgFanc> mGetMsgFanc = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_userinfo);
        Intent intent = getIntent();

        mContext=GetMsgFanCActivity.this;
        mSp = mContext.getSharedPreferences("userInfo", mContext.MODE_WORLD_READABLE);
        initEvents();
        initViews();
    }

    @Override
    protected void initViews() {

        mSettingListView = (ListView)findViewById(R.id.set_list_listview);
        tv_layout_title= (TextView) findViewById(R.id.tv_title_layout);
        tv_layout_title.setText("获取消息界面");

    }

    @Override
    protected void initEvents() {

        init();

    }
    private void init(){



        fetchAddrList();

    }


    protected void fetchAddrList()
    {
        this.putAsyncTask(new AsyncTask<Void, Void, Integer>() {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();

            }

            @Override
            protected Integer doInBackground(Void... voids) {
                ArrayList<String> paramList = new ArrayList<String>();
                ArrayList<String> valueList = new ArrayList<String>();
                List<String> resaulList = new ArrayList<>();
                paramList.add("DoType");
                paramList.add("UserType");
                paramList.add("UserId");

                valueList.add("1");
                valueList.add("0");
                valueList.add("0");

                SoapObject soapObject = WebServiceUtils.GetWebServiceInfo("GetMsgFunc", paramList, valueList);

                if (soapObject != null) {
                    SoapObject soap1 = (SoapObject) soapObject.getProperty("GetMsgFuncResult");
                    if (soap1 == null || soap1.getPropertyCount() == 0) return 0;
                    SoapObject childs = (SoapObject) soap1.getProperty(1);
                    if (childs == null || childs.getPropertyCount() == 0) return 0;
                    SoapObject soap2 = (SoapObject) childs.getProperty(0);
                    if (soap2 == null) return 0;
                    ///
                    Object obj = null;
                    for (int i = 0; i < soap2.getPropertyCount(); i++) {
                        SoapObject soap3 = (SoapObject) soap2.getProperty(i);
                        if (soap3 != null) {
                            //AddrInfo info = new AddrInfo();
                            obj = soap3.getProperty(1);
                            if (obj != null) {
                                //info.strAddr = obj.toString().trim();
                                itemString.add(obj.toString().trim());
                                //test(obj.toString().trim());
                            }
/*
obj = soap3.getProperty(1);
if (obj != null) {
info.strRoomName = obj.toString().trim();//校区
}
if (soap3.getPropertyCount() >= 3) {
obj = soap3.getProperty(2);
if (obj != null) {
info.strSchool = obj.toString().trim();//学校
}
}
*/
                            //itemString.add(info);
                            //DataManagerUtils.getInstance().addAddrInfoList(info);
                        }

                    }

                }

                return 1;
            }

            @Override
            protected void onPostExecute(Integer integer) {
                super.onPostExecute(integer);
                FillListView();
                //dismissLoadingDialog();
                //fillAdapterList();
            }
        });
        //.execute();
    }
    public void FillListView()
    {
        //itemString.add(TestStr);

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(GetMsgFanCActivity.this, android.R.layout.simple_expandable_list_item_1, itemString);
        mSettingListView.setAdapter(arrayAdapter);
        mSettingListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int positon, long l) {
                ArrayList<String>messarraylist=new ArrayList<String>();
                messarraylist=  mArrayList.get(positon);
                Intent intent = new Intent();
                intent.setClass(GetMsgFanCActivity.this, News_Activity.class);
                intent.putExtra("position", messarraylist);
                startActivity(intent);


            }
        });


    }



}

3 个解决方案

#1


mArrayList你根本就没有值,显示的值是itemString,两者的size不一样,数据不同步,肯定会越界

#2


引用 1 楼 sagittarius1988 的回复:
mArrayList你根本就没有值,显示的值是itemString,两者的size不一样,数据不同步,肯定会越界
那要怎么改

#3


引用 2 楼 qq_32396601 的回复:
Quote: 引用 1 楼 sagittarius1988 的回复:

mArrayList你根本就没有值,显示的值是itemString,两者的size不一样,数据不同步,肯定会越界
那要怎么改


public void onItemClick(AdapterView<?> adapterView, View view, int positon, long l) {
                String msgStr=  itemString.get(positon);
                Intent intent = new Intent();
                intent.setClass(GetMsgFanCActivity.this, News_Activity.class);
                intent.putExtra("position", msgStr);
                startActivity(intent);
            }

#1


mArrayList你根本就没有值,显示的值是itemString,两者的size不一样,数据不同步,肯定会越界

#2


引用 1 楼 sagittarius1988 的回复:
mArrayList你根本就没有值,显示的值是itemString,两者的size不一样,数据不同步,肯定会越界
那要怎么改

#3


引用 2 楼 qq_32396601 的回复:
Quote: 引用 1 楼 sagittarius1988 的回复:

mArrayList你根本就没有值,显示的值是itemString,两者的size不一样,数据不同步,肯定会越界
那要怎么改


public void onItemClick(AdapterView<?> adapterView, View view, int positon, long l) {
                String msgStr=  itemString.get(positon);
                Intent intent = new Intent();
                intent.setClass(GetMsgFanCActivity.this, News_Activity.class);
                intent.putExtra("position", msgStr);
                startActivity(intent);
            }