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

时间:2017-02-07 04:07:41

标签: java android android-studio android-fragments

我已经按照GalleryListview(内置分隔标签)的教程进行操作,这两个教程都在导航抽屉内的同一片段环境中工作。现在我应该做的就是将这两个片段合并在一起,所以当我点击名为“Gallery”的Listview时,它将显示画廊照片的不同导演的列表视图。现在,当我点击某个列表视图时,应用程序将不会响应,从而在此过程中退出。

我的TabGallery片段代码是“LISTVIEW”

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

现在这里包含logcat

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中宣布过两次包,也不能在androidmanifest.xml中声明它。

2 个答案:

答案 0 :(得分:1)

你应该像这样打开

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();

答案 1 :(得分:0)

您正尝试将Fragment用作Activity

  

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

这是向您fragment的{​​{1}}添加viewGroup的方式:

activity

您需要在此Google Guide

中详细了解如何使用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();
相关问题