0

I have an issue I cannot seem to find the answer for.

I've been browsing the web for hours, I found people with similar issues and errors, but those problems have been solved with proper code which I already did implement ( error is not due to my code being broken. Up to date tutorials backs me up..(?) ), in my case my app worked fine during the majority of it's developing stage. But as I implemented an adView, my app suddenly started getting this error. I removed the Ad implementation but the error remains..

  1. I have been looking at: Android Fragment no view found for ID? But had no luck there.
  2. I've Rebuilt, cleaned, restarted both android studio and my computer.
  3. I peaked into R to see if fragment_layout had the assigned Id '0x7f09006d'.
  4. I've tried changing name from fragment_layout to anything else, but no luck, also made a new content_main.xml to try it.
  5. I'm using 27.1.1 implementations. Compile version 27, target 27, min 17.

I'm having a activity_main.xml with a drawer layout, that (app_bar_main.xml).

app_bar_main.xml does a (content_main.xml).

Content_main.xml's rootView has the ID of fragment_layout.

(This is standard template when creating a drawer layout Activity)

This is how I change to the fragments, using fragment_layout

         compare_loan compareLoan = new compare_loan();
         getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, compareLoan, compareLoan.getTag()).commit();

(I get the following error:

java.lang.IllegalArgumentException: No view found for id 0x7f09006d (com.something.somethingelse.appname:id/fragment_layout) for fragment compare_loan{aee705c #0 id=0x7f09006d} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1422) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 12-13 17:57:48.000 25339-29001/system_process E/memtrack: Couldn't load memtrack module

Anyone has any clue? As said it has been working fine for days. No big changes could have affected this. Only thing I can point out is adView implementation. Which is now removed from 'implementation' now.

I hope this makes sense for you guys. This is my first post. I hope to provide a solution if I find one.

alfredo-fredo
  • 356
  • 2
  • 7
  • "Content_main.xml has the ID of fragment_layout." – Do you mean the root `View` in the `content_main` layout has the `fragment_layout` ID? Do you happen to have an ID specified on the `` for it in the `app_bar_main` layout? – Mike M. Dec 13 '18 at 20:34
  • Yes the rootView has ID fragment_layout, sorry. Yes the in app_bar_main.xml has the ID "include". What I did now was that I put the ID to the app_bar_main.xml's ("include") insted of the fragment_layout, and having the fragment_layout (content_main.xml's rootView) "show in" app_bar_main.xml. `getSupportFragmentManager().beginTransaction().replace(R.id.include, compareLoan, compareLoan.getTag()).commit();`... Originally --> `getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, compareLoan, compareLoan.getTag()).commit();` – alfredo-fredo Dec 13 '18 at 22:01
  • This solution seems to have solved the problem. But if it's the "right" way I don't know. I'm still confused as to why my code "broke" in the first place, `getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, compareLoan, compareLoan.getTag()).commit();` worked in the first place, until it started throwing exceptions, without me making any changes, literally from one minute to another. @MikeM. I appreciate your engagement. – alfredo-fredo Dec 13 '18 at 22:11
  • I'm not sure how things changed on your end, but the issue stems from a somewhat hidden, unknown "feature" regarding ``s. The ID on an `` overrides the ID on the root `View` in the included layout. In your case, your `ViewGroup` was ending up with ID `include`, which is why the `FragmentManager` couldn't find `fragment_layout`. This might've happened if you added that ID on the `` after your initial tests, but I find it most often happens when users change the included layout; e.g., moving a previously inner `FrameLayout` to be the root `View`. – Mike M. Dec 13 '18 at 22:44
  • I just reread our comments, and I realized that I didn't really address your main concern. Yes, this is the "right" way. You just had a minor glitch 'cause of that ID mix-up. Don't sweat it too much. When you're working with relatively large projects with a bunch of moving parts, it's pretty easy to have something slip in unintentionally. It's only about as bad as a typo, and now you know another thing to look for next time, should this happen again. Cheers! – Mike M. Dec 14 '18 at 01:31
  • 1
    Okay, nice explaination! Good thing we could clear this out. Yep, totally, now I know for the next time! Thank you @MikeM. I wish you happy holidays to come. – alfredo-fredo Dec 14 '18 at 02:33

0 Answers0