找不到显式活动类(Android Studio 片段)



我遵循了图库和列表视图(内部有单独的选项卡(的教程,两者都在我的导航抽屉内处理相同的片段环境。现在我应该做的是将这两个片段合并在一起,所以当我点击名为"画廊"的列表视图时,它将显示画廊照片的不同类别的列表视图。现在,当我单击某个列表视图时,该应用程序将不会响应,从而在此过程中退出。

我的 TabGallery 片段代码,这是一个"列表视图">

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0) {
                    Intent intent = new Intent(getActivity(), GalleryFragment.class);
                    startActivity(intent);
                }
            }
        });

假设 GalleryFragment.class 包含 Galleryimages

现在这里包含日志猫

02-07 11:22:06.732 30384-30384/? I/art: Late-enabling -Xcheck:jni
02-07 11:22:06.740 30384-30384/? V/appproc: App process: starting thread pool.
02-07 11:22:06.757 30384-30398/? I/art: Debugger is no longer active
02-07 11:22:06.760 30384-30384/? D/Proxy: setHttpRequestCheckHandler
02-07 11:22:06.781 30384-30384/? D/wangcy9: setStatusIcon occur wrong theme!
02-07 11:22:06.856 30384-30408/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-07 11:22:06.863 30384-30384/? D/ViewRootImpl: loadSystemProperties PersistDebugEvent: false RoDebugEvent: false
02-07 11:22:06.883 30384-30408/? I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BR.1.1.3_RB1.05.01.00.032.017_msm8916_64_LA.BR.1.1.3_RB1__release_AU ()
                                               OpenGL ES Shader Compiler Version: E031.25.03.04
                                               Build Date: 04/29/15 Wed
                                               Local Branch: mybranch9502464
                                               Remote Branch: quic/LA.BR.1.1.3_rb1.12
                                               Local Patches: NONE
                                               Reconstruct Branch: AU_LINUX_ANDROID_LA.BR.1.1.3_RB1.05.01.00.032.017 + 26a3cba + 6f69ea6 + 8bc2bc8 + 649fcde + a52cccf + dbf281f + 15f0bf8 +  NOTHING
02-07 11:22:06.884 30384-30408/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-07 11:22:06.898 30384-30408/? D/OpenGLRenderer: Enabling debug mode 0
02-07 11:22:06.903 30384-30408/? I/qdutils: PartialUpdate status: Disabled
02-07 11:22:06.903 30384-30408/? I/qdutils: Left Align: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Width Align: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Top Align: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Height Align: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Min ROI Width: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Min ROI Height: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Needs ROI Merge: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Dynamic Fps: Disabled
02-07 11:22:06.903 30384-30408/? I/qdutils: Min Panel fps: 0
02-07 11:22:06.903 30384-30408/? I/qdutils: Max Panel fps: 0
02-07 11:22:06.985 30384-30384/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@28dbd8c7 time:52879049
02-07 11:22:11.553 30384-30384/com.example.guitarista.citem I/Timeline: Timeline: Activity_launch_request id:com.example.guitarista.citem time:52883617
02-07 11:22:11.563 30384-30384/com.example.guitarista.citem I/Choreographer: Skipped 36 frames!  The application may be doing too much work on its main thread.
02-07 11:22:11.608 30384-30384/com.example.guitarista.citem W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-07 11:22:11.627 30384-30384/com.example.guitarista.citem D/wangcy9: setStatusIcon occur wrong theme!
02-07 11:22:11.994 30384-30384/com.example.guitarista.citem D/ViewRootImpl: loadSystemProperties PersistDebugEvent: false RoDebugEvent: false
02-07 11:22:12.117 30384-30384/com.example.guitarista.citem I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@1d62e93e time:52884181
02-07 11:22:12.855 30384-30384/com.example.guitarista.citem W/PathParser: Points are too far apart 4.000000596046461
02-07 11:22:14.670 30384-30384/com.example.guitarista.citem W/PathParser: Points are too far apart 4.000000596046461
02-07 11:22:15.742 30384-30384/com.example.guitarista.citem I/Timeline: Timeline: Activity_launch_request id:com.example.guitarista.citem time:52887806
02-07 11:22:15.744 30384-30384/com.example.guitarista.citem D/AndroidRuntime: Shutting down VM
02-07 11:22:15.746 30384-30384/com.example.guitarista.citem E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.example.guitarista.citem, PID: 30384
                                                                              android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.guitarista.citem/com.example.guitarista.citem.Gallery.GalleryFragment}; have you declared this activity in your AndroidManifest.xml?
                                                                                  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
                                                                                  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
                                                                                  at android.app.Activity.startActivityForResult(Activity.java:3806)
                                                                                  at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
                                                                                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                                                                                  at android.support.v4.app.ActivityCompatJB.startActivityForResult(ActivityCompatJB.java:26)
                                                                                  at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:146)
                                                                                  at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:929)
                                                                                  at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:1043)
                                                                                  at android.support.v4.app.Fragment.startActivity(Fragment.java:932)
                                                                                  at android.support.v4.app.Fragment.startActivity(Fragment.java:921)
                                                                                  at com.example.guitarista.citem.Attendees.TabAllFragment$1.onItemClick(TabAllFragment.java:62)
                                                                                  at android.widget.AdapterView.performItemClick(AdapterView.java:305)
                                                                                  at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
                                                                                  at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
                                                                                  at android.widget.AbsListView$3.run(AbsListView.java:3864)
                                                                                  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:5322)
                                                                                  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:905)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
02-07 11:22:18.448 30384-30384/com.example.guitarista.citem I/Process: Sending signal. PID: 30384 SIG: 9

现在我的怀疑是logcat中的这一行代码

com.example.guitarista.citem/com.example.guitarista.citem.Gallery.GalleryFragment

尽管我什至从未在我的 GalleryFragment 中声明过两次该包,我什至无法在我的 android 清单中声明它.xml .

你应该像这样打开

GalleryFragment fr = new GalleryFragment();
Bundle args = new Bundle();
fr.setArguments(args);
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.gallery_fragment, fr);
fragmentTransaction.commit();

您正在尝试将Fragment用作Activity

您可以将片段视为活动的模块化部分,该部分具有自己的生命周期,接收自己的输入事件,并且可以在活动运行时添加或删除该事件(有点像可以在不同活动中重用的"子活动"(。

这是将fragment添加到activity viewGroup的方法:

ArticleFragment newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putInt(ArticleFragment.ARG_POSITION, position);
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();

您需要在此Google指南中阅读更多如何使用fragment

相关内容

最新更新