im trying to set background to my activity but it throws nullpointer exception everytime
here is my code
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
RelativeLayout layout = (RelativeLayout) findViewById(R.layout.activity_main);
layout.setBackground(getResources().getDrawable(R.drawable.welcome_2));
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable( getResources().getDrawable(R.drawable.welcome_1) );
} else {
layout.setBackground(getResources().getDrawable(R.drawable.welcome));
}
setContentView(R.layout.activity_main);
and this is my layout
<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" >
move
before
and defined
relativelayout
Id inXML