Unexpected NullpointExpection inside a setter [duplicate] - java

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I'm trying to do a simple operation: click a button and show a custom DialogFragment, but I'm getting a NullPointExpection and I can't figure out why.
mAlertDialog.java:
public class mAlertDialog extends DialogFragment {
TextView title;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_invalid_time, container, false);
title = (TextView)view.findViewById(R.id.titleText);
return view;
}
public void setTheTitle(String title) {
this.title.setText(title);
}
}
Showing mAlertDialog:
mAlertDialog dialog = new mAlertDialog();
dialog.setTheTitle(getActivity().getString(R.string.invalidTimeTitle));
dialog.show(fm, "InvalidTime");
Error message:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at m.inschool8.Objects.mAlertDialog.setTheTitle(mAlertDialog.java:20)
at m.inschool8.bSubjects.Fragment_Subjects$55.onClick(Fragment_Subjects.java:2654)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

The title is still null when you are calling
mAlertDialog dialog = new mAlertDialog();
dialog.setTheTitle(getActivity().getString(R.string.invalidTimeTitle));
so what you can do is
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_invalid_time, container, false);
title = (TextView)view.findViewById(R.id.titleText);
setTheTitle(getActivity().getString(R.string.invalidTimeTitle));
return view;
}
// call it
mAlertDialog dialog = new mAlertDialog();
dialog.show(fm, "InvalidTime");

Your title is null until the DialogFragment is shown causing onCreateView to kick-in. Hence change the order as below:
mAlertDialog dialog = new mAlertDialog();
dialog.show(fm, "InvalidTime");
dialog.setTheTitle(getActivity().getString(R.string.invalidTimeTitle));

Related

App crashes when running code from in fragment

I am making my first app in android studio. So far I have built a bottom navigation bar using fragments. I am now trying to add a calendar feature to one of the fragments, I have copied a tutorial using activities to run the code and think there is a problem with using "View".
This is the code to open for the nav bar to open the fragment.
#Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.home:
getSupportFragmentManager().beginTransaction().replace(R.id.container,homeFragment).commit();
return true;
case R.id.calendar:
getSupportFragmentManager().beginTransaction().replace(R.id.container,calendarFragment).commit();
return true;
case R.id.wellbeing:
getSupportFragmentManager().beginTransaction().replace(R.id.container,wellbeingFragment).commit();
return true;
}
return false;
This is java in my calendar fragment, which when opened from the navigation bar crashes the app
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
initWidgets();
selectedDate = LocalDate.now();
setMonthView();
return inflater.inflate(R.layout.fragment_calendar, container, false);
}
private void initWidgets()
{
calendarRecyclerView = requireView().findViewById(R.id.calendarRecyclerView);
monthYearText = requireView().findViewById(R.id.monthYearTV);
}
private void setMonthView()
{
monthYearText.setText(monthYearFromDate(selectedDate));
ArrayList<String> daysInMonth = daysInMonthArray(selectedDate);
CalendarAdapter calendarAdapter = new CalendarAdapter(daysInMonth, this);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(),7);
calendarRecyclerView.setLayoutManager(layoutManager);
calendarRecyclerView.setAdapter(calendarAdapter);
}
This is the error message I receive in my logcat
2022-05-12 12:45:05.305 10950-10950/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 10950
java.lang.IllegalStateException: Fragment CalendarFragment{c4de180} (94b1c782-ca39-403f-b45b-5d0d7a042f15 id=0x7f080087) did not return a View from onCreateView() or this was called before onCreateView().
at androidx.fragment.app.Fragment.requireView(Fragment.java:1964)
at com.example.myapplication.CalendarFragment.initWidgets(CalendarFragment.java:41)
at com.example.myapplication.CalendarFragment.onCreateView(CalendarFragment.java:30)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I believe there is no error in the calendar code and is something to do with onCreateView in the fragment code.
You cannot call requireView() before returning a non-null value from onCreateView().
Move these lines
initWidgets();
selectedDate = LocalDate.now();
setMonthView();
(where initWidgets() calls requireView()) from onCreateView() to e.g. onViewCreated().
Yes it crashes because findViewById wasn't called from the fragment_calendar layout before returning inflater therefore anything called after the return statement will not be executed and will return a NullPointerException. Unless you override onViewCreated method and put down the codes
So to avoid that, you need to override onViewCreated method or you must return view. Remember, if you want to return view then all codes or public methods must be reached before the return view statement. Else, it'll crash due to exception
Check this codes, it'll fix it correctly
public class TestFragment extends Fragment {
RecyclerView calendarRecyclerView;
TextView monthYearText;
#Nullable
#org.jetbrains.annotations.Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable #org.jetbrains.annotations.Nullable ViewGroup container, #Nullable #org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
selectedDate = LocalDate.now();
return inflater.inflate(R.layout.fragment_calendar, container, false);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable #org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initWidgets(view);
setMonthView();
}
private void initWidgets(View view) {
calendarRecyclerView = view.findViewById(R.id.calendarRecyclerView);
monthYearText = view.findViewById(R.id.monthYearTV);
}
private void setMonthView() {
monthYearText.setText(monthYearFromDate(selectedDate));
ArrayList<String> daysInMonth = daysInMonthArray(selectedDate);
CalendarAdapter calendarAdapter = new CalendarAdapter(daysInMonth, getActivity());
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), 7);
calendarRecyclerView.setLayoutManager(layoutManager);
calendarAdapter.setAdapter(calendarAdapter);
}
}

Issue with Setting Text on TextView outside the OnCreate Method [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
i have been creating an App that uses Fragments Mostly
here is how it is supposed to work, on the Home Fragment i click a button that takes me to another Fragment for filling information
on this fragment when I click a button a Dialog Fragment opens and I select a City Name then Submit, it dismisses the Dialog and is supposed to SetText on a TextView.
I use an interface that calls a method on the City Selection fragment in order to set the Text. here is some Code
Declaration for the EditText
EditText editText_From;
Setting finding the View
OnCreate
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_trip_date, container, false);
editText_From = view.findViewById(R.id.editText_From);
return view;
}
public void setSelectedCity(String city)
{
Log.i("<<269>>", "Setting Text on Edit Text <<269>>:" + city);
editText_From.setText(city);
}
This Method below is supposed to set text for the my EditText or TextView
public void setSelectedCity(String city)
{
Log.i("<<269>>", "Setting Text on Edit Text <<269>>:" + city);
selectedCityConfirmed = city;
editText_From.setText(city);
}
the App Crashes on EditText with the Following Error Message,
02-16 19:37:43.928 26582-26582/com.example.bob2609.busticketingapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bob2609.busticketingapp, PID: 26582
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v4.app.FragmentActivity.findViewById(int)' on a null object reference
at com.example.bob2609.busticketingapp.TripDateFragment.setSelectedCity(TripDateFragment.java:188)
at com.example.bob2609.busticketingapp.MainActivity.selectedCity(MainActivity.java:176)
at com.example.bob2609.busticketingapp.LocationSelector$1.onItemClick(LocationSelector.java:69)
at android.widget.AdapterView.performItemClick(AdapterView.java:313)
at android.widget.AbsListView.performItemClick(AbsListView.java:1201)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3195)
at android.widget.AbsListView$3.run(AbsListView.java:4138)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
The Interface Method on MainActivity
#Override
public void selectedCity(String city)
{
tripDateFragment.setSelectedCity(city);
}
Anyone knows a way around this?
Why are you declaring again Textview again in onCreate Method?
Declare outside the onCreate and Find the View using "findViewByID" inside on create.

Android view is null object reference inside fragment

i'm having a hard time with some code. I am using sliding tabs with 2 fragment. Inside one of my fragment i'm trying to get a LinearLayout and add some stuff in it but everytime i try to do getView().findViewByID() I got null object reference
I'm calling the function after the onCreateView() I tried making a variable of type View and putting the View that i inflate in the onCreateView in it but i keeps getting the same error. I also tried putting a if() before to check if view isnt null , but even with this , I get null object reference. Can someone help me ?
public class listAlarmFragment extends Fragment{
public View view = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle bundle){
View v = inflater.inflate(R.layout.list_alarm,vg,false);
view = v;
return v;
}
public void showAlarm(Cursor c){
if(view != null) { //even with that check, I got a null pointer exception
LinearLayout baseList = (LinearLayout) view.findViewById(R.id.baseList); // NullPointerException: Attempt to invoke virtual method on a null object reference
}
}
}
Replacing view with getView() doesnt change anything.
This is how I'm calling the function from the Main Activity
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
Fragment c = adapter.getItem(0);
((listAlarmFragment)(c)).showAlarm(dbHelper.getAlarm()); // where I call the function
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
I'm opening this fragment at the beggining when my app open. It crashs when im trying to switch to another fragment.
here is the stack trace :
04-02 18:41:54.615 31584-31584/al.demo.alarmmanagerdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: al.demo.alarmmanagerdemo, PID: 31584
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at al.demo.alarmmanagerdemo.fragment.listAlarmFragment.showAlarm(listAlarmFragment.java:83)
at al.demo.alarmmanagerdemo.MainActivity$1.onPageSelected(MainActivity.java:54)
at android.support.v4.view.ViewPager.dispatchOnPageSelected(ViewPager.java:1971)
at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:689)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:673)
at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:2288)
at android.view.View.dispatchTouchEvent(View.java:10779)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2858)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2534)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:605)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1895)
at android.app.Activity.dispatchTouchEvent(Activity.java:3241)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:67)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:67)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:567)
at android.view.View.dispatchPointerEvent(View.java:11008)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5155)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5007)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4532)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4585)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4551)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4684)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4559)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4741)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4532)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4585)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4551)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4559)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4532)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7024)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6985)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7202)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6776)
04-02 18:41:54.615 31584-31584/al.demo.alarmmanagerdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1510)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1400)
I would do something like this,
public class listAlarmFragment extends Fragment{
//public View view = null; // no need
private LinearLayout baseList;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle bundle){
View v = inflater.inflate(R.layout.list_alarm,vg,false);
baseList = (LinearLayout) v.findViewById(R.id.baseList);
//view = v; no need
return v;
}
public void showAlarm(Cursor c){
if(baseList!=null){
//do something with your baseList
}
}
}
Also check R.id.baseList exists in the layout xml R.layout.list_alarm.
and it should be LinearLayout with
id=#+id/baseList

Not able to pass string value from one fragment to another [duplicate]

This question already has answers here:
How to pass values between Fragments
(18 answers)
Closed 5 years ago.
I know there are so many qustions regarding this , but none of them are solving my problem
I want to pass a string variable from one fragment to other, here is the code I did. but I am getting error (I will show the error)
from first fragment I did
Desc_1 ldf = new Desc_1 ();
Bundle args = new Bundle();
args.putString("YourKey", "YourValue");
ldf.setArguments(args);
getFragmentManager().beginTransaction().add(R.id.frame, ldf).commit();
and incoming second fragment I did like
public class Desc_1 extends Fragment {
public Desc_1() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootview=inflater.inflate(R.layout.fragment_desc_1,container,false);
String value = getArguments().getString("YourKey");
Toast.makeText(getActivity(), value,
Toast.LENGTH_LONG).show();
return rootview;
}
}
I am getting error like
07-27 20:31:06.386 26816-26816/com.example.jaison.newsclient E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jaison.newsclient, PID: 26816
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
at layout.Desc_1.onCreateView(Desc_1.java:34)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2063)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:725)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:861)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
try this :
Bundle bundle = getArguments();
if(bundle != null)
String value = bundle.getString("YourKey");
Just check if getArguments() is not null inside your fragment, and then inside the curly braces add your code
Example:
Bundle bundle_arguments = getArguments();
if(bundle_arguments != null) {
// your code
}
Please check this answer for passing values between fragments
https://stackoverflow.com/a/27626004/5065318

NullPointerException on ImageView in Fragment in FragmentPagerAdapter

I have a bunch of fragments in a FragmentPagerAdapter with one ImageView in side each fragment. If I swipe really fast this error comes up:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wilsapp.wilsapp, PID: 21319
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at com.wilsapp.wilsapp.Fragments.BuyerHomePageFragment9$DownloadImageTask.onPostExecute(BuyerHomePageFragment9.java:212)
at com.wilsapp.wilsapp.Fragments.BuyerHomePageFragment9$DownloadImageTask.onPostExecute(BuyerHomePageFragment9.java:192)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
If I swipe slowly then it works perfectly fine.
Android Code (code is the same for each fragment. Code in AsyncTask):
protected void onPostExecute(Bitmap result) {
try {
ImageView img = (ImageView) getView().findViewById(R.id.ProductOneImageView);
img.setImageBitmap(result);
}catch (Exception e){
ImageView img = (ImageView) getView().findViewById(R.id.ProductOneImageView);
int id = getResources().getIdentifier("com.wilsapp.wilsapp:drawable/" + "error", null, null);
img.setImageResource(id);
}
}
Android onCreatView method:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_buyer_home_page, container, false);
return view;
}
how can i avoid the NullPointerException?
ImageView img = (ImageView) getView().findViewById(R.id.ProductFiveImageView);
ImageView need initialize in onCreateView. A case of you getView() return null...
Add your initialization snippet in onViewCreated method instead of onCreateView. it will ensure that imageview will be initialize after your view is inflated.
#Override
public void onViewCreated(final View view, #Nullable Bundle savedInstanceState) {
ImageView img = (ImageView) view.findViewById(R.id.ProductFiveImageView);
img.setImageBitmap(result);
}
ImageView img = (ImageView) getView().findViewById(R.id.ProductFiveImageView);
hi You can add a judgment,getView Whether to null, and Fault tolerant processing!

Categories