In my main activity, I'm using navigation component to switch between the fragments,
I'm fetching data from my backend, the data received successfully then I'm updating my UI,
I'm getting this error for one of my fragment,
for this code
Converters.getSpannableString(
""name,
0,
2,
ContextCompat.getColor(
requireActivity(),
R.color.lightSpanRed
)
on this line I'm getting crash:- ContextCompat.getColor(requireActivity(),R.color.lightSpanRed)
the Logs is
java.lang.IllegalStateException: Fragment MainFragment{ce669b1} (aa1b0f2b-de44-443a-834e-
ee9e10df261b)} not attached to an activity.
at androidx.fragment.app.Fragment.requireActivity(Fragment.java:833)
I'm getting this error, can anyone provide the best answer
question from:
https://stackoverflow.com/questions/65949126/im-getting-not-attached-to-an-activity-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…