android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
So I'll post what I think is the solution to my problem. After adding a single line to my above code giving the ViewPager
a "random" ID; it managed to fix my problem.
At first I was convinced that setting your own ID is bad practice, but apparently there are legitimate ways of doing this. Namely by creating an ids.xml file and letting the Android ecosystem generate an ID for you. I recommend checking out these SO posts for more information - here and here.
Otherwise, I would recommend just creating an XML file for your layout and getting the ViewPager
in your Activity
(instead of programmatically instantiating it), but ultimately it all depends on what you're trying to accomplish.
Resources$NotFoundException: Unable to find resource ID #0xffffffff using NestedScrollView with Motionlayout
Okay, I've solved my issue. There were two problems: My colors and my layout id's.
First I've deleted every custom black and white color and used @android:color/white
and @android:color/black
. Second, I've given EVERY layout (constraintlayout
, my motionlayout
, textview
etc) a CUSTOM ID.
The scrolling behavior now works, the only problem I have is, that I get W/MotionLayout: WARNING could not find view id -1
and that scrolling is really laggy. Will open another question for this error.
android.content.res.Resources$NotFoundException: Resource ID #0xffffffff. cannot make search view with query
searchView.backgroundColorResource = Color.WHITE
is the problem. You need to set a resource id here but Color.WHITE
is a color value, not a resource id. You can try
searchView.backgroundColorResource = android.R.color.white
android.content.res.Resources$NotFoundException: Unable to find resource ID
This problem is interesting. After debugging your sample app for a while this is my finding:
- The
resource id
that is missing is the id of created fragment -CardBackFragment
. - The
resource id
is given dynamically after you replace and commit the fragment
For prof of what I have just said, here is a screenshot when I was debugging your app notice the id that is shown:
And here is the missing id that the debugger told it was missing:
And to be clear, the newContainerId
tis translated into hex id that is here (sorry for my bad english)
So what happen here?
The answer lies in the way the code is execute the line:myHolderflipcard.cardView.setVisibility(View.GONE);
That was trigger after you commit the fragment to be shown.
Here is what happen:
When you told the card view to be gone, the last item is removed from ui -> Because it is removed from ui and it is the last item on the recycler view -> the height of the recycler view
is shorten to minimize the view
. The bug happen for the last item because the recycler view
understand that the row layout
that hold the question is empty and it is the last item -> the last item is instead transfer to the question row above. Meanwhile, the thread that insert the fragment
into your framelayout
is not done. So when it's done and it try to find the containerid
, it cannot find it. Hence, the crash.
So the way to fix it is to wait for the frame to be added completely then you remove the question
Here is the fix:
Remove
myHolderflipcard.cardView.setVisibility(View.GONE);
line from yourflipcard
methodOn the outside create a:
private MyHolder curHolder;
Create a runnable to hide the CardView:
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
Log.d("mId", String.valueOf(curHolder.container.getId()));
curHolder.cardView.setVisibility(View.GONE);// handler.postDelayed(this, 500);
}
};post it after the commit is done:
Fragment f;
f = new CardBackFragment();
// Then just replace the recycler view fragment as usually
((FragmentActivity) context).getFragmentManager().beginTransaction()
.setCustomAnimations(
R.animator.card_flip_right_in,
R.animator.card_flip_right_out,
R.animator.card_flip_left_in,
R.animator.card_flip_left_out)
.addToBackStack(null)
.replace(newContainerId, f).commit();
// Once all fragment replacement is done we can show the hidden container
handler.post(runnable);
Although it happens really fast. You can use handler.postDelayed(runnable, 100);
instead if you want to ensure that the fragment is successfully replaced under any circumstances
And here is the full code (since I'm really bad at english, so I post it just in case)
private void flipcard(final RecyclerView.ViewHolder holder)
{
final MyHolder myHolderflipcard= (MyHolder) holder;
String nim=mysr_id.get(Integer.parseInt(mpref.getradio_button_value()));
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher(nim);
if (matcher.find())
{
currentsrid=Integer.parseInt(matcher.group(0));
if (currentsrid!=flag)
{
flag = Integer.parseInt(matcher.group(0));
// Delete old fragment
int containerId = myHolderflipcard.container.getId();// Get container id
Fragment oldFragment = ((FragmentActivity) context).getFragmentManager().findFragmentById(containerId);
if(oldFragment != null)
{
((FragmentActivity) context).getFragmentManager().beginTransaction().remove(oldFragment).commit();
}
int newContainerId = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
newContainerId = View.generateViewId();
}
// Set the new Id to our know fragment container
myHolderflipcard.container.setId(newContainerId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
curHolder = myHolderflipcard;
}
// Just for Testing we are going to create a new fragment according
// if the view position is pair one fragment type is created, if not
// a different one is used.
{
Fragment f;
f = new CardBackFragment();
// Then just replace the recycler view fragment as usually
((FragmentActivity) context).getFragmentManager().beginTransaction()
.setCustomAnimations(
R.animator.card_flip_right_in,
R.animator.card_flip_right_out,
R.animator.card_flip_left_in,
R.animator.card_flip_left_out)
.addToBackStack(null)
.replace(newContainerId, f).commit();
// Once all fragment replacement is done we can show the hidden container
handler.post(runnable);
//myHolderflipcard.container.setVisibility(View.VISIBLE);
//myHolderflipcard.radioGroup.setVisibility(View.GONE);
//myHolderflipcard.tvQuestion.setVisibility(View.GONE);
// myHolderflipcard.cardView.setVisibility(View.GONE);
}
}else
{
// backtoorignal=false;
// ((FragmentActivity)context). getFragmentManager().popBackStack();
}
}
}
private MyHolder curHolder;
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
Log.d("mId", String.valueOf(curHolder.container.getId()));
curHolder.cardView.setVisibility(View.GONE);
}
};
Android messed up R.java unable to find resource ID #0xffffffff
If your view doesn't have a id, then getId()
will return -1. So it comes to be 0xffffffff.
It seems that your focusableViews
not only contain mybutton1, but also some others with no id. That's the problem.
Related Topics
Updated Sdk Version, Getting Classnotfoundexception: Android.Support.V4.View.Viewpager
How to Use Getlistview() in Activity
Capturing Images with Mediastore.Action_Image_Capture Intent in Android
How to Move an Image from Left to Right in Android
R.Java Disappears After Project Clean
Send Intent from Service to Activity
Xamarin Forms Android App Crashes Running Debug with VS Android Emulator
Why Is Listview.Getcheckeditempositions() Not Returning Correct Values
How to Create Datepicker and Timepicker Dialogs in Fragment Class
How to Add a Hint in Spinner in Xml
Button in Custom Android Toast
How to Detect When the User Launches Another App? (Android)
Sqlite Simultaneous Reading and Writing
Getting Header from Response (Retrofit/Okhttp Client)
Access_Coarse_Location Permission Gives a Cell Tower Precision on Android