0

App crashes when I click on ImageView.

Trying to navigate to a fragment with card view after clicking on Image View. There is fragment ghosting problem as well but that code is commented for now. I tried fixing that as well but was not successful.

This is my code:

mainroute.java:

 wiButton.setOnClickListener(new View.OnClickListener() {
            @Override
            //@SuppressWarnings("ResourceType")
            public void onClick(View v) {

                FragmentManager mFragmentManager = getActivity().getSupportFragmentManager();//.findFragmentByTag("WifiFragment");

                /*if (mFragment == null) {
                    // wifiFragment = WifiFragment.newInstance();
                    mFragmentTransaction.add(R.id.WifiLayout, wifiFragment, "WifiFragment");
                } else {
                    wifiFragment = (WifiFragment) mFragment;*/

                    FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
                    WifiFragment wifiFragment = new WifiFragment();
                    mFragmentTransaction.add(R.id.WifiLayout, wifiFragment);
                    mFragmentTransaction.commit();
                    fICardView.setVisibility(View.VISIBLE); 
                }

            });

the logcat is:

2019-02-15 21:32:08.960 15780-15780/com.felixxiong.android.city E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.felixxiong.android.city, PID: 15780
    java.lang.IllegalArgumentException: No view found for id 0x7f07002f (com.penghaoxiong.android.cityexploration:id/WifiLayout) for fragment WifiFragment{6e89def #4 id=0x7f07002f}
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit

...
2019-02-15 21:32:09.774 3275-15841/? E/EntrySyncManager: Cannot determine account name: drop request
2019-02-15 21:32:09.775 3275-15841/? E/NowController: Failed to access data from EntryProvider. ExecutionException.
    java.util.concurrent.ExecutionException: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3
        at com.google.common.util.concurrent.d.eA(SourceFile:85)
        at com.google.common.util.concurrent.d.get(SourceFile:23)
        at com.google.common.util.concurrent.l.get(SourceFile:2)
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbB(SourceFile:49)
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbA(SourceFile:181)
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2)
        at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)
        at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
        at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
        at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)
     Caused by: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.ar.az(Unknown Source:4)
        at com.google.common.util.concurrent.q.ap(SourceFile:7)
        at com.google.common.util.concurrent.p.run(SourceFile:32)
        at com.google.common.util.concurrent.bt.execute(SourceFile:3)
        at com.google.common.util.concurrent.d.b(SourceFile:275)
        at com.google.common.util.concurrent.d.addListener(SourceFile:135)
        at com.google.common.util.concurrent.p.b(SourceFile:3)
        at com.google.android.apps.gsa.shared.util.concurrent.h.a(SourceFile:16)
        at com.google.android.apps.gsa.shared.util.concurrent.h.a(SourceFile:13)
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbB(SourceFile:47)
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbA(SourceFile:181) 
        at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2) 
        at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4) 
        at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4) 
        at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
        at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6) 
2019-02-15 21:32:09.777 1814-1827/? E/memtrack: Couldn't load memtrack module

I was tried this post:Android Fragment no view found for ID?

I tried to find my r.java flie,i was find my wifilayout id: r.java:

public static final int WifiLayout=0x7f07002f;

The same issue is occuring in another function in this fragment.

I tried to getChildFragmentManager():

noButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentManager mFragmentManager = getChildFragmentManager();
                FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
                NoteFragment noteFragment = new NoteFragment();
                mFragmentTransaction.add(R.id.NoteLayout, noteFragment);
                mFragmentTransaction.commit();
                fICardView.setVisibility(View.VISIBLE);
            }

        });

Thanks a lot.

Surbhi Aggarwal
  • 777
  • 8
  • 25
  • So what are these `R.id....Layout`s you're trying to use as container layout for the fragment? Note the container layout needs to be already there (e.g. in the hosting activity), it cannot be part of the fragment being added. – laalto Feb 15 '19 at 15:59
  • I tried to make a CardView, and dynamic switching ImageView to make CardView show, this cardView was in mainActivity XML, and to load fragment, and have ghosting bug(mainRoute.java-comment code). In old vision, this was successful to on click... – Felix Xiong Feb 16 '19 at 07:07

1 Answers1

0

If your layout file WifiLayout is in the layout folder, you have to use R.layout.WifiLayout instead of R.id.WifiLayout.

And that's the same with all of your layout files.

Best

Maxouille
  • 2,729
  • 2
  • 19
  • 42
  • My `WifiLayout` was the `android:id` in xml file,isn't the layout flie name. when i was change `id` to `layout`, android studio was tip me ‘Expected resource of type id’... – Felix Xiong Feb 16 '19 at 03:56
  • Can you post your layout xml file plz ? – Maxouille Feb 17 '19 at 20:10
  • Just the fragment have a cardview, and visibility is gone, and other XML:wifi frag XML and note frag XML layout have a ID… – Felix Xiong Mar 03 '19 at 12:19