(FrameLayout里)findViewById(R.id.land)返回NULL
问题描述:
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
答
在XML你有
android:id="@+id/land"
在Java代码中你有
if(findViewById(R.id.landT)==null)
您需要删除杂散t将其应R.id.land
我删除它,问题出现,直到NW –
我不知道我明白了什么你是说,只有当你删除t时才会出现问题。 – Ben
删除t后,问题没有结束,直到现在findViewById(R.id.land)= null –