我有一個可怕的時間試圖找出我的Andriod應用程序中的問題。 代碼運行良好,然後我更新到Andriod Studio 0.2.9,並且還做出了一些 更改,現在我被卡住了。android佈局導致崩潰在actionbar addtab
我有以下活動佈局,爲了簡潔起見,我在其中剪掉了一些較低的 級別的項目。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".ViewActivity">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/rl_view"
android:visibility="visible"
>
<LinearLayout
android:id="@+id/ll_view_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
... content omitted ...
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp"
>
... content omitted ...
</LinearLayout>
<LinearLayout
android:id="@+id/ll_view_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
>
... content omitted ...
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_view_data"
android:layout_below="@+id/ll_view_header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:showDividers="middle"
android:divider="@drawable/level_divider"
android:dividerPadding="20dp"
>
<RelativeLayout
android:id="@+id/rl_levels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
... content omitted ...
</RelativeLayout>
<ListView
android:id="@+id/listView_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:choiceMode="singleChoice"
android:longClickable="true"
/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
的問題是,每當我包括+ ID/listView_View項目,我想在OnCreate方法中添加分頁時,得到一個崩潰 。預覽器的佈局看起來不錯, 也不會顯示錯誤。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
mDefault_drawable = getResources().getDrawable(R.drawable.ic_item_question);
mHeader_drawable = getResources().getDrawable(R.drawable.ic_header_icon);
// define defaults
index_in_modc = -1;
mView_layout = ViewLayout.VL_DATA;
view_style = 0;
// Set up the action bar to show tabs.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// For each of the sections in the app, add a tab to the action bar.
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_view_view).setText(R.string.view_view).setTabListener(this));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_view_tags).setText(R.string.view_manage_tags).setTabListener(this));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_home).setText(R.string.main_home).setTabListener(this));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_help).setText(R.string.help).setTabListener(this));
...
如果我刪除+ id/listView_View項目,那麼代碼似乎工作,我沒有崩潰。我試過 所有類型的重建,評論各種事情等。我很懷疑由於0.2.9更新, 或可能庫不匹配,但很多天後,我無法弄清楚它的錯誤。任何幫助或建議 是多餘的歡迎!
你的logcat說什麼? –