2015-06-18 81 views
0

僅適用於Android 4.0.3-4.0.4的某些設備上的應用程序僅適用於標籤。 IDE Eclipse。 日誌如下。 如果設置高度最大30dp,我可以防止崩潰。僅適用於Android 4.0.3-4.0.4的某些設備上的TabHost應用程序崩潰

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> 

代碼標籤:

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); 
    }  
} 

登錄與崩潰:

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) 
+0

可能太多的嵌套佈局。 – M4rtini

+0

我不認爲這是過度嵌套。我們有更多的應用程序。 –

回答

0

java.lang.StackOverflowError當運行程序的堆棧的深度超過某個平臺或虛擬機的具體限制拋出。通常情況下,只有當程序變爲無限遞歸時纔會出現這種情況,但它也可能發生在正確書寫(但深度遞歸)的程序中。

  1. 變化onPreExecute()方法:

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

progressDialog = ProgressDialog.show(MySpaceTabbedPanelActivity.this, "", getString(R.string.update)); 
  • 在你的代碼稱爲asyncTaskonResume()方法,所以它可能會發生遞歸和虛擬機拋出錯誤。 使asynctask調用一次,並從onResume()方法中分離出asynctask。
  • +0

    感謝repy,Jon。我評論了asynctask代碼,無論如何這次崩潰 –

    +0

    無論如何,這次崩潰意味着你有沒有改變progressDialog中的上下文? –

    +0

    已更改。它沒有幫助。 –

    相關問題