在android列表视图中向下滚动时出现StackoverflowException

时间:2011-12-19 16:03:44

标签: android xml

我有一个标签主机,其内容又是标签主机。 主标签主机是第一个,所有内容首先显示。 在第二个标签主机中,我有一个tabactivity,其内容是listview。 当我向下滚动时,第二个列表视图崩溃并显示消息:

12-19 18:00:59.262: E/AndroidRuntime(1296): FATAL EXCEPTION: main
12-19 18:00:59.262: E/AndroidRuntime(1296): java.lang.StackOverflowError
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.text.Styled.measureText(Styled.java:430)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.text.Layout.measureText(Layout.java:1655)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.text.Layout.getLineMax(Layout.java:689)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.text.Layout.draw(Layout.java:340)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.text.BoringLayout.draw(BoringLayout.java:365)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.TextView.onDraw(TextView.java:4050)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6740)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.buildDrawingCache(View.java:6502)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.getDrawingCache(View.java:6288)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1565)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.AbsListView.dispatchDraw(AbsListView.java:1365)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.ListView.dispatchDraw(ListView.java:3046)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6846)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.AbsListView.draw(AbsListView.java:2257)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.View.draw(View.java:6743)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewRoot.draw(ViewRoot.java:1407)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
12-19 18:00:59.262: E/AndroidRuntime(1296):     at android.os.Handler.dispatchMessage(Handler.java:99)

这里我使用listview

public class Standings extends Activity implements OnItemClickListener {


    @Override
     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.standings_layout);

            CompetitionCommand compCmd = new CompetitionCommand();
            ArrayList teams = compCmd.getTeams();


            ListView newsListView = (ListView) findViewById(R.id.lv_standings);

            StandingsListAdapter adapter = new StandingsListAdapter(this,teams);
            newsListView.setAdapter(adapter);   
            adapter.notifyDataSetChanged();
            newsListView.invalidate();
            newsListView.setOnItemClickListener(this);


    }
public class StandingsListAdapter extends BaseAdapter {



     private LayoutInflater mInflater;
     private ArrayList teams;

     public StandingsListAdapter(Context context,ArrayList aTeams) 
     {
            this.mInflater = LayoutInflater.from(context);
            this.teams=aTeams;
     }

     public int getCount() 
     {
         return teams.size();
     }

     public Object getItem(int position) 
     {
         return position;
     }

     public long getItemId(int position) 
     {
         return position;
     }


     public View getView(int position, View convertView, ViewGroup parent) 
     {


         ViewHolder holder;

         Team team = teams.get(position);

         if (convertView == null) 
         {
             convertView = mInflater.inflate(R.layout.list_stand_row, null);
             holder = new ViewHolder();
             holder.st_place = (TextView) convertView.findViewById(R.id.tv_team_place);
             holder.st_team_name = (TextView) convertView.findViewById(R.id.tv_team_name);
             holder.st_played= (TextView) convertView.findViewById(R.id.tv_team_played);
             holder.st_won= (TextView) convertView.findViewById(R.id.tv_team_won);
             holder.st_drawn = (TextView) convertView.findViewById(R.id.tv_team_drawn);
             holder.st_lost= (TextView) convertView.findViewById(R.id.tv_team_lost);
             holder.st_goals_for= (TextView) convertView.findViewById(R.id.tv_team_goals_for);
             holder.st_goals_against= (TextView) convertView.findViewById(R.id.tv_team_goals_against);
             holder.st_points =(TextView) convertView.findViewById(R.id.tv_team_points);
             convertView.setTag(holder);
         }
         else 
         {
             holder = (ViewHolder)convertView.getTag();
         }


         holder.st_place.setText(team.getPlace());
         holder.st_team_name.setText(team.getTeam_name());
         holder.st_played.setText(team.getPlayed());
         holder.st_won.setText(team.getWon());
         holder.st_drawn.setText(team.getDrawn());
         holder.st_lost.setText(team.getLost());
         holder.st_goals_for.setText(team.getGoals_for());
         holder.st_goals_against.setText(team.getGoals_against());
         holder.st_points.setText(team.getPoints());


         return convertView;
     }



        static class ViewHolder 
        {
                 TextView st_team_name;
                 TextView st_place;
                 TextView st_played;
                 TextView st_won;
                 TextView st_drawn;
                 TextView st_lost;
                 TextView st_points;
                 TextView st_goals_for;
                 TextView st_goals_against;
                 TextView st_points_deduction;
         }

}

2 个答案:

答案 0 :(得分:0)

只需检查弹出列表视图的布局。如果你使用嵌套的Linearlayouts,那么这种问题就会出现。喜欢RelativeLayouts。通货膨胀要快得多。

同时阅读this

答案 1 :(得分:0)

你的R.layout.standings_layout必须是其他

中的很多LinearLayouts