App crash on TabHost on some devices only for Android 4.0.3-4.0.4

386 Views Asked by At

App crahses on tag only on some devices only for Android 4.0.3-4.0.4. IDE Eclipse. Log is below. I can prevent crash if for set height maximum 30dp.

layout\my_space_tabbed.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/anudroid"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@drawable/fond"
              android:gravity="center_horizontal"
              android:orientation="vertical">

    <LinearLayout
            android:id="@+id/top_menu"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/header">
    </LinearLayout>

    <RelativeLayout android:layout_width="match_parent"
                    android:layout_height="match_parent">

        <include layout="@layout/no_license"/>

        <TabHost
                android:id="@android:id/tabhost"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                <LinearLayout android:layout_width="match_parent"
                              android:layout_height="48dp"
                              android:background="@drawable/header"
                              android:gravity="center">
                    <TabWidget
                            android:id="@android:id/tabs"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>
                </LinearLayout>

                <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="match_parent"
                        android:layout_height="0dip"
                        android:layout_weight="1" />

            </LinearLayout>
        </TabHost>
    </RelativeLayout>
</LinearLayout>

Code with tab:

 public class MySpaceTabbedPanelActivity extends TabActivity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_space_tabbed);
        // tabs

        addTab(getString(R.string.Index), IndexMySpaceGroup.class);
        addTab(getString(R.string.Tees), MySpaceTeesGroup.class);
        addTab(getString(R.string.Friendly_games), FriendlyGamesGroup.class);

        final int white = MySpaceTabbedPanelActivity.this.getResources().getColor(R.color.WHITE_COLOR);
        TextView tv = (TextView) getTabHost().getTabWidget().getChildAt(0).findViewById(R.id.title);
        tv.setTextColor(white);
        getTabHost().setOnTabChangedListener(new OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {
                TabHost tabHost = getTabHost();
                for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
                    TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(R.id.title); //unselected
                    tv.setTextColor(MySpaceTabbedPanelActivity.this.getResources().getColor(R.color.black_color));
                }

                int tabIndex = 0;
                if(tabId.equals("tab" + getString(R.string.Index))) {
                    tabIndex = 0;
                } else if(tabId.equals("tab" + getString(R.string.Tees))) {
                    tabIndex = 1;
                } else if(tabId.equals("tab" + getString(R.string.Friendly_games))) {
                    tabIndex = 2;
                }
                TextView tv = (TextView) tabHost.getTabWidget().getChildAt(tabIndex).findViewById(R.id.title);
                tv.setTextColor(white);
            }
        });

    }


    @Override
    protected void onResume() {
        super.onResume();

        // >> topMenu
        int[] topMenuButtons;
        if (Content.from(this).hasLogonPlayer()){
            findViewById(android.R.id.tabhost).setVisibility(View.VISIBLE);
            findViewById(R.id.no_license1).setVisibility(View.INVISIBLE);
            topMenuButtons = new int[]{R.id.UserButton, R.id.updateButton, R.id.infoButton};
        }else{
            findViewById(android.R.id.tabhost).setVisibility(View.INVISIBLE);
            findViewById(R.id.no_license1).setVisibility(View.VISIBLE);
            topMenuButtons = new int[]{R.id.signupButton, R.id.infoButton};
        }

        LinearLayout topMenu = (LinearLayout)findViewById (R.id.top_menu);
        topMenu.removeAllViews();
        topMenu.addView(new TopMenuComponent(this, topMenuButtons) {
            @Override
            public void onUpdate() {
                new AsyncTask<Object, Object, Object>() {
                    private ProgressDialog progressDialog;
                    @Override
                    protected void onPreExecute() {
                        progressDialog = ProgressDialog.show(getTabGroup(), "", getString(R.string.update));
                    }
                    @Override
                    protected Object doInBackground(Object... objects) {
                        getContent().queryPlayerInfo();
                        getContent().queryFriendlyGames();
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Object o) {
                        getContent().onPostExecute();
                        progressDialog.dismiss();
                    }
                }.execute();
            }
        });
        // <

    }

    private void addTab(String labelId, Class<? extends Activity> c){
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator_my_space, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);

        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }



    private TabGroup getTabGroup() {
        return getIntent().getParcelableExtra("tabGroup");
    }

    private Content getContent(){
        return Content.from(this);
    }       
}

Log with crash:

java.lang.StackOverflowError
at android.graphics.Paint.getTextRunAdvances(Paint.java:1785)
at android.graphics.Paint.getTextRunAdvances(Paint.java:1758)
at android.text.TextLine.handleText(TextLine.java:930)
at android.text.TextLine.handleRun(TextLine.java:1153)
at android.text.TextLine.measureRun(TextLine.java:589)
at android.text.TextLine.measure(TextLine.java:453)
at android.text.TextLine.metrics(TextLine.java:427)
at android.text.Layout.getLineExtent(Layout.java:943)
at android.text.Layout.draw(Layout.java:406)
at android.text.BoringLayout.draw(BoringLayout.java:400)
at android.widget.TextView.onDraw(TextView.java:5307)
at android.view.View.draw(View.java:11120)
at android.view.View.getDisplayList(View.java:10559)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.draw(View.java:11123)
at android.view.View.getDisplayList(View.java:10559)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.draw(View.java:11123)
at android.view.View.getDisplayList(View.java:10559)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.getDisplayList(View.java:10557)
at android.view.ViewGroup.drawChild(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2503)
at android.view.View.draw(View.java:11123)
at android.widget.FrameLayout.draw(FrameLayout.java:450)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2276)
at android.view.View.getDisplayList(View.java:10559)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:876)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2092)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1816)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
1

There are 1 best solutions below

6
On

java.lang.StackOverflowError thrown when the depth of the stack of the running program exceeds some platform or VM specific limit. Typically, this will occur only when a program becomes infinitely recursive, but it can also occur in correctly written (but deeply recursive) programs.

  1. change in onPreExecute() method :

    progressDialog = ProgressDialog.show(getTabGroup(), "", getString(R.string.update));
    

to

progressDialog = ProgressDialog.show(MySpaceTabbedPanelActivity.this, "", getString(R.string.update));
  1. In your code you called the asyncTask in onResume() method, so it might be possible for recursive occurring and VM throws error. make the asynctask call once and seperate asynctask from onResume() method.