Android的layout_main里面include了layout_a,layout_b,然后初始化的时候隐藏layout_a,b的时候出现空指针
应该怎么办?<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:...
应该怎么办?
<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"
tools:context=".MainActivity" >
<include layout="@layout/game"/>
<include layout="@layout/introduce"/>
<include layout="@layout/report"/>
</RelativeLayout>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initMyButton();
try {
rLayout_game=(RelativeLayout) findViewById(R.layout.game);
rLayout_introduce=(RelativeLayout) findViewById(R.layout.introduce);
rLayout_report=(RelativeLayout) findViewById(R.layout.report);
rLayout_game.setVisibility(View.INVISIBLE);
rLayout_report.setVisibility(View.INVISIBLE);
rLayout_introduce.setVisibility(View.GONE);
} catch (Exception e) {
// TODO: handle exception
Log.e("Layout", "ErrorMessage:"+e.getMessage());
e.printStackTrace();
}
} 展开
<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"
tools:context=".MainActivity" >
<include layout="@layout/game"/>
<include layout="@layout/introduce"/>
<include layout="@layout/report"/>
</RelativeLayout>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initMyButton();
try {
rLayout_game=(RelativeLayout) findViewById(R.layout.game);
rLayout_introduce=(RelativeLayout) findViewById(R.layout.introduce);
rLayout_report=(RelativeLayout) findViewById(R.layout.report);
rLayout_game.setVisibility(View.INVISIBLE);
rLayout_report.setVisibility(View.INVISIBLE);
rLayout_introduce.setVisibility(View.GONE);
} catch (Exception e) {
// TODO: handle exception
Log.e("Layout", "ErrorMessage:"+e.getMessage());
e.printStackTrace();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询