2016-09-21 177 views
0
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    if(findViewById(R.id.landT)==null) 
    { 
     mTwoPane=false; 
    } 
    else{ 
     mTwoPane=true; 
    } 
    FrameLayout f =(FrameLayout) findViewById(R.id.land); 
} 

// XML activity_main(FrameLayout裏)findViewById(R.id.land)返回NULL

<LinearLayout 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:baselineAligned="false" 
android:divider="?android:attr/dividerHorizontal" 
android:orientation="horizontal" 
tools:context="com.example.progg.movie.ConnFragment" 
android:id="@+id/landT"> 



<fragment 
    android:id="@+id/connfragment" 
    android:name="com.example.progg.movie.ConnFragment" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="0.4" 
    tools:layout="@android:layout/list_content" /> 

<FrameLayout 
    android:id="@+id/land" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="0.6" /> 

這個程序的移動應用程序我有任務轉換的應用程序出現在平板電腦把我面對這個問題我不能解決這個問題, (FrameLayout裏)findViewById(R.id.land)返回NULL,和f = NULL

回答

0

在XML你有

android:id="@+id/land" 

在Java代碼中你有

if(findViewById(R.id.landT)==null) 

您需要刪除雜散t將其應R.id.land

+0

我刪除它,問題出現,直到NW –

+0

我不知道我明白了什麼你是說,只有當你刪除t時纔會出現問題。 – Ben

+0

刪除t後,問題沒有結束,直到現在findViewById(R.id.land)= null –