为什么在视图翻录器中出现stackoverflow错误?

时间:2011-11-16 05:01:01

标签: android viewflipper

我在android应用程序中使用viewflipper。

我的应用程序在tabhost中有tabhost。当我点击“主页”选项卡时 - >点击饮食按钮 - >然后它会显示新的tabhost,如早餐,午餐等。

当我在午餐标签中使用视图鳍状肢时,它有两个按钮主页办公室,然后两个按钮开关布局通过视图鳍状肢,但是当午餐标签打开时,它会显示stackoverflow错误。

我也尝试layoutinflater和其他选项期望视图鳍状肢,但它显示相同的错误。

这是logcat错误

    11-16 10:08:48.229: ERROR/AndroidRuntime(223): Uncaught handler: thread main exiting due to uncaught exception
    11-16 10:08:48.258: ERROR/AndroidRuntime(223): java.lang.StackOverflowError
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.text.Layout.measureText(Layout.java:1601)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.text.Layout.getLineMax(Layout.java:655)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.text.Layout.draw(Layout.java:311)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.text.BoringLayout.draw(BoringLayout.java:356)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.TextView.onDraw(TextView.java:4032)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.CompoundButton.onDraw(CompoundButton.java:229)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6274)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6277)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6277)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6380)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526) 
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6277)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6277)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6277)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
    11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View.draw(View.java:6277)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at   android.view.View.draw(View.java:6277)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1883)
     11-16 10:08:48.258: ERROR/AndroidRuntime(223):     at android.view.View

代码在这里

    RelativeLayout rel1,rel2,rel3,rel4,rel5,rel6,
rel_Yes,rel_No;

     ImageButton rad_Yes,rad_No;
      TextView lbl_Yes,lbl_No;
         boolean yesNoChk=false;
      boolean have_lunch=false;

       RelativeLayout flip1,flip2;

      ViewFlipper vf;
    StringBuffer pasta,rice,soup,legmues,l_pasta;

     LinearLayout lin1;
      int i,j;
      ToggleButton [] imgArray1;
      ToggleButton [] imgArray2;
      ToggleButton [] imgArray3;
      ToggleButton [] imgArray4;
      ToggleButton [] imgArray5;
       RelativeLayout item ;

       Button btn;
       StringBuffer msg;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
setContentView(R.layout.lunch);





rad_Yes = (ImageButton) findViewById(R.id.lunch_radio_office);
rad_No = (ImageButton) findViewById(R.id.lunch_radio_home); 

    vf = (ViewFlipper)findViewById(R.id.ViewFlipper01);

flip1=(RelativeLayout)findViewById(R.id.flip1);
flip2=(RelativeLayout)findViewById(R.id.flip2);

rad_Yes.setOnClickListener(yesClickListener);
rad_No.setOnClickListener(noClickListener);

item = (RelativeLayout)findViewById(R.id.main);
     rel1 = (RelativeLayout) findViewById(R.id.main_rel1);
  rel2 = (RelativeLayout) findViewById(R.id.main_rel2);
  rel3 = (RelativeLayout) findViewById(R.id.main_rel3);
 rel4 = (RelativeLayout) findViewById(R.id.main_rel4);
   if(!yesNoChk)
{ 
rel5 = (RelativeLayout) findViewById(R.id.main_rel5);
 }   


imgArray1 = new ToggleButton[7];
 for(j=0;j<imgArray1.length;j++)
 {
     imgArray1[j] = (ToggleButton) rel1.getChildAt(j);
     imgArray1[j].setOnClickListener(this);

 }

 imgArray2 = new ToggleButton[7];
 for(j=0;j<imgArray2.length;j++)
 {
     imgArray2[j] = (ToggleButton) rel2.getChildAt(j);
     imgArray2[j].setOnClickListener(this);

 }
 imgArray3 = new ToggleButton[7];
 for(j=0;j<imgArray3.length;j++)
 {
     imgArray3[j] = (ToggleButton) rel3.getChildAt(j);
     imgArray3[j].setOnClickListener(this);

 }
 imgArray4 = new ToggleButton[7];
 for(j=0;j<imgArray4.length;j++)
 {
     imgArray4[j] = (ToggleButton) rel4.getChildAt(j);
     imgArray4[j].setOnClickListener(this);

 }

 if(!yesNoChk)
 { 
     imgArray5 = new ToggleButton[7];
     for(j=0;j<imgArray5.length;j++)
     {
         imgArray5[j] = (ToggleButton) rel5.getChildAt(j);
         imgArray5[j].setOnClickListener(this);

     }
 }
}





OnClickListener yesClickListener = new OnClickListener() {
    public void onClick(View v) {
        if(!yesNoChk){
            rad_Yes.setImageResource(R.drawable.selectradiobtn);
            rad_No.setImageResource(R.drawable.radiobtn);
            yesNoChk = true;


            vf.getChildAt(1).setVisibility(View.VISIBLE);
            vf.getChildAt(0).setVisibility(View.GONE);


        }

    }
};



OnClickListener noClickListener = new OnClickListener() {
    public void onClick(View v) {

            rad_No.setImageResource(R.drawable.selectradiobtn);
            rad_Yes.setImageResource(R.drawable.radiobtn);
            yesNoChk = false;

             vf.getChildAt(0).setVisibility(View.VISIBLE);
             vf.getChildAt(1).setVisibility(View.GONE);




    }
};

1 个答案:

答案 0 :(得分:1)

哦!我明白了,我需要更改对我来说容易的文本框值。因为我在tab中的选项卡中的布局。因此它无法清除堆栈,因此最好的方法是清除堆栈,然后替换我们想要的文本视图的名称。