恢复值时空指针异常

时间:2012-01-25 12:53:35

标签: android

protected void onRestoreInstanceState(Bundle savedInstanceState)
{
    super.onRestoreInstanceState(savedInstanceState);
    for(int i=0;
    i<teeth.length;
    i++)
    {
        teeth[i]=(Integer) savedInstanceState.get("Id"+"["+i+"]");
        if(teeth[i]!=0)
        {
            teeth[i]=i+1;
            backselection.add(teeth[i]);
            Ateeth[i].setBackgroundResource(imgid[i]);
            currentselection.setText("CurrentSelection:"+backselection);
        }
    }
}
protected void onSaveInstanceState(Bundle outState)
{
    for(int i=0;
    i<teeth.length;
    i++)
    {
        outState.putInt("Id"+"["+i+"]", teeth[i]);
    }
    super.onSaveInstanceState(outState);
}

1 个答案:

答案 0 :(得分:0)

尝试使用getInt()

savedInstanceState.getInt("Id"+"["+i+"]", 0);  //0 is default value