当我单击ImageView时,应用程序崩溃。
在单击“图像视图”后尝试导航至具有卡视图的片段。也有片段重影问题,但该代码现在已注释。 我也尝试修复此问题,但未成功。
这是我的代码:
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);
}
});
logcat是:
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
我曾尝试过这篇文章:Android Fragment no view found for ID?
我试图找到我的r.java文件,我找到了我的wifilayout ID: r.java:
public static final int WifiLayout=0x7f07002f;
此片段的另一个函数中发生了相同的问题。
我试图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);
}
});
非常感谢。
答案 0 :(得分:0)
如果布局文件WifiLayout位于布局文件夹中,则必须使用R.layout.WifiLayout
而不是R.id.WifiLayout
。
所有布局文件都一样。
最佳