Replacing Fragment Throws NotFoundException

100 views
Skip to first unread message

Benny Thompson

unread,
Jul 11, 2015, 6:36:26 PM7/11/15
to mac...@googlegroups.com
I am trying to implement a main fragment that gets changed with the click of a button.

My main activity has a section like this with the frame layout for my fragments I'm switching between:

        l[FrameLayout]()
         
<~ id(Id.mainFragment)
         
<~ matchParent,

In my initial fragment I have something like this (using the macroid-extras from 47 Degrees repo):

        w[Button]
         
<~ text("+")
         
<~ ExtraLpTweaks.weightedWidth(1)
         
<~ On.click(replaceFragment(builder = f[ActionFragment], id = Id.mainFragment, tag = Some(Tag.mainFragment))),

But whenever I click the button I end up with:

07-11 18:28:18.577    6531-6531/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: myapp.android, PID: 6531
    android.content.res.Resources$NotFoundException: Unable to find resource ID #0x3ea
            at android.content.res.Resources.getResourceName(Resources.java:2070)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
            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)

Any ideas what migth be going on? 

Martin Mauch

unread,
Jul 11, 2015, 8:33:38 PM7/11/15
to mac...@googlegroups.com
I'm just guessing here:
You call Id.mainFragment once from an activity and once from a fragment, both probably include the IdGenerator trait, right?
It might be that the generated IDs are only identical for a given name within the same instance, i.e. Id.mainFragment in the activity generates a different Id than the Id.mainFragment you use in the fragment to look the FrameLayout up.

Can you try calling Id.mainFragment only in the activity and passing the value to the fragment via constructor/newInstance?

Benny Thompson

unread,
Jul 11, 2015, 8:42:36 PM7/11/15
to mac...@googlegroups.com
I think it's one of those things that you stare at too long and just can't see clearly anymore but your suggestion made too much sense when I read it. I just tried with IdGeneration as a mixin on a companion object of my main activity and using that reference everywhere and it worked! 

Now I'm left wondering if there's a convention for this kind of thing?

Thanks!

Nick Stanchenko

unread,
Jul 12, 2015, 6:21:28 AM7/12/15
to mac...@googlegroups.com, ben.d....@gmail.com
Hey,

Sorry, I’m late to the party :) What do you guys think about this? https://github.com/macroid/macroid/pull/60

Nick
Reply all
Reply to author
Forward
0 new messages