I've been working on making my own custom ImageView class on Android. I've read the documentation on layouts, fragments, activities and ImageView.
I've looked at Stack posts on how to create an ImageView programatically but I've run into a snag I can't seem find a solution to (reading the top hits for searching the above error did not apply to my issue).
I have an activity, and inside that activity I have a fragment. Inside the fragment I am creating an ImageView (its called iImage but its just an extended ImageView class).
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
// Inflate the layout for this fragment
iImage image = new iImage(getActivity());
image.setImageResource(R.drawable.name_splash);
LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(1500,1100);
image.setLayoutParams(par);
container.addView(image);
View rootView = inflater.inflate(R.layout.fragment_edit_photo, container, false);
return rootView;
}
However, when I run the app, it loads, and it works just fine, however I get this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{co.name.app/co.name.app.CameraEditorActivity}: java.lang.NullPointerException: Layout parameters cannot be null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
....
Caused by: java.lang.NullPointerException: Layout parameters cannot be null
at android.view.View.setLayoutParams(View.java:11470)
at co.name.app.EditPhotoFragment.onCreateView(EditPhotoFragment.java:89)
Can you advise what the underlying issue is?