I am trying to change the background of another activity by passing in the photo they select from their phones photo gallery to the layout. However I keep getting an error of :
Caused by: java.lang.NullPointerException
at com.example.shawn.slidingexample.BackgroundOptionSlider.onActivityResult(BackgroundOptionSlider.java:105)
at android.app.Activity.dispatchActivityResult(Activity.java:5778)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3710)
I dont understand why I am getting this error since I do he same exact thing for the current activity that I am in and it works fine...
InputStream inputStream = getContentResolver().openInputStream(selectedImage);
Drawable uploadedPic = Drawable.createFromStream(inputStream, selectedImage.toString());
RelativeLayout layout = (RelativeLayout) findViewById(R.id.updated_background);
layout.setBackground(uploadedPic);//this works
RelativeLayout home = (RelativeLayout) findViewById(R.id.home);
home.setBackground(uploadedPic);//error here
Here is my fragment XML:
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/home"
tools:context=".MainActivity$PlaceholderFragment">
<TextView android:id="@+id/menu_home" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="MENU HOME PAGE"/>
And here is the activity XML:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout android:id="@+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.example.shawn.slidingexample.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />