2011-10-14 50 views
0

我是全新的android開發和代碼崩潰在setContentView(R.layout.main)。我不知道爲什麼。我已經嘗試過標準清潔並且重新構建並重新啓動eclipse。Android應用程序崩潰setContentView

主要代碼:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

} 

的main.xml代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/tabhost" android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <LinearLayout android:orientation="vertical" 
      android:layout_width="fill_parent" android:layout_height="fill_parent"> 
      <View android:layout_width="fill_parent" android:layout_height="0.5dip" 
       android:background="#000" /> 
      <TabWidget android:id="@android:id/tabs" 
       android:layout_width="fill_parent" android:layout_height="wrap_content" 
       android:layout_marginLeft="0dip" android:layout_marginRight="0dip" /> 
      <View android:layout_width="fill_parent" android:layout_height="2dip" 
       android:background="#696969" /> 
      <View android:layout_width="fill_parent" android:layout_height="2dip" 
       android:background="#000" /> 
      <FrameLayout android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 
+0

你能從logcat獲得Stacktrace嗎? –

+0

我該怎麼做?對不起,我是全新的android。我通常做iPhone,但讓自己進入一個新項目。 – Bryan1234321

+0

如果您在ADT中使用Eclipse,請在窗口菜單下添加View。 –

回答

3

從TabHost刪除的xmlns。佈局xml文件中應該只有一個xmlns。

<TabHost 
    android:id="@android:id/tabhost" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
+0

你是什麼意思由xmins ???而我將如何去呢? – Bryan1234321

+0

僅用於根目錄佈局的xmlns屬性。應該從佈局文件中刪除任何錯位的xmlns屬性。 當我放入代碼時,你只需要用我的代碼替換你的 PH7

+0

我拿出了xmins,可悲的是應用程序啓動時仍然崩潰。還有什麼可能會出錯的嗎? – Bryan1234321