应用程序崩溃加载片段

时间:2018-03-17 02:23:14

标签: java android android-studio android-fragments

尝试用片段替换占位符容器时,我的应用程序会立即崩溃。

加载片段的方法很简单:

private void loadFragment(Fragment fragment) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragHolder, 
fragment).commit();
}

我只是这么称呼:

Fragment fragment = new MyFragment();
loadFragment(fragment);

我要替换的容器fragHolder是一个FrameLayout,它位于一个水平的LinearLayout中。您是否有可能只将碎片放入某些容器中?

根据网络上的消息来源,我加载片段的方式似乎没有错。

如果需要,请询问更多信息。

编辑:

从LogCat for myapp输出错误:

   03-17 03:38:02.758 3179-3179/? E/android.os.Debug: failed to load memtrack module: -2
03-17 03:38:03.049 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:38:03.049 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:38:03.049 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:38:03.146 1530-2967/system_process E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:38:05.505 3190-3190/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: mycompany.myname.myapp, PID: 3190
                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{mycompany.myname.myapp/mycompany.myname.myapp.MainActivity}: java.lang.RuntimeException: mycompany.myname.myapp.MainActivity@285a72d1 must implement OnFragmentInteractionListener
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                     at android.os.Looper.loop(Looper.java:135)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                     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:899)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                                                  Caused by: java.lang.RuntimeException: mycompany.myname.myapp.MainActivity@285a72d1 must implement OnFragmentInteractionListener
                                                     at mycompany.myname.myapp.MyFragment.onAttach(MyFragment.java:83)
                                                     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1231)
                                                     at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1085)
                                                     at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:976)
                                                     at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:95)
                                                     at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146)
                                                     at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                     at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                                                     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                                                     at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                                                     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
                                                     at android.app.Activity.performStart(Activity.java:5953)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
                                                     at android.app.ActivityThread.access$800(ActivityThread.java:144) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                     at android.os.Looper.loop(Looper.java:135) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:5221) 
                                                     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:899) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
03-17 03:38:05.811 1530-1912/system_process E/ActivityManager: Invalid thumbnail dimensions: 504x504
03-17 03:38:05.877 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:38:05.878 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:38:05.878 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:38:05.926 1530-2967/system_process E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:38:18.278 3445-3445/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-17 03:38:18.278 3445-3445/? E/android.os.Debug: failed to load memtrack module: -2
03-17 03:38:18.698 3465-3465/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-17 03:38:18.698 3465-3465/? E/android.os.Debug: failed to load memtrack module: -2
03-17 03:38:19.178 3482-3482/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-17 03:38:19.178 3482-3482/? E/android.os.Debug: failed to load memtrack module: -2
03-17 03:38:22.537 3497-3497/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-17 03:38:22.537 3497-3497/? E/android.os.Debug: failed to load memtrack module: -2
03-17 03:38:22.891 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:38:22.891 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:38:22.891 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:38:22.963 1530-2967/system_process E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:38:26.068 3508-3508/mycompany.myname.myapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                      Process: mycompany.myname.myapp, PID: 3508
                                                                                      java.lang.RuntimeException: Unable to start activity ComponentInfo{mycompany.myname.myapp/mycompany.myname.myapp.MainActivity}: java.lang.RuntimeException: mycompany.myname.myapp.MainActivity@285a72d1 must implement OnFragmentInteractionListener
                                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
                                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                          at android.os.Looper.loop(Looper.java:135)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                                                          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:899)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                                                                                       Caused by: java.lang.RuntimeException: mycompany.myname.myapp.MainActivity@285a72d1 must implement OnFragmentInteractionListener
                                                                                          at mycompany.myname.myapp.MyFragment.onAttach(MyFragment.java:83)
                                                                                          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1231)
                                                                                          at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1085)
                                                                                          at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:976)
                                                                                          at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:95)
                                                                                          at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146)
                                                                                          at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                          at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                                          at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                                                                                          at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                                                                                          at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                                                                                          at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
                                                                                          at android.app.Activity.performStart(Activity.java:5953)
                                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
                                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
                                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:144) 
                                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                          at android.os.Looper.loop(Looper.java:135) 
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:5221) 
                                                                                          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:899) 
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
03-17 03:38:26.373 1530-1718/system_process E/ActivityManager: Invalid thumbnail dimensions: 504x504
03-17 03:38:26.427 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:38:26.428 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:38:26.428 1530-2967/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:38:26.487 1530-2967/system_process E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:39:00.025 1638-2034/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:39:33.922 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:39:33.922 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:39:33.922 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:39:33.968 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:39:33.968 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:39:33.968 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:40:00.025 1638-2034/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:41:00.026 1638-2034/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:41:33.885 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:41:33.886 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:41:33.886 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:41:33.933 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:41:33.933 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:41:33.933 2611-2628/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:42:00.027 1638-2034/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:43:26.673 8147-8147/? E/memtrack: Couldn't load memtrack module (No such file or directory)
03-17 03:43:26.673 8147-8147/? E/android.os.Debug: failed to load memtrack module: -2
03-17 03:45:00.033 1638-2034/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer
03-17 03:45:34.116 2611-2630/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:45:34.116 2611-2630/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:45:34.116 2611-2630/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:45:34.159 2611-2630/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
03-17 03:45:34.159 2611-2630/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-17 03:45:34.159 2611-2630/com.google.android.gms.unstable E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-17 03:46:00.028 1638-2034/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer

之前还有更多,但是我不会允许我发布所有内容,我认为有很多我正在运行模拟器?我选择了与我相关的内容,但不要犹豫,要求任何具体的内容。

1 个答案:

答案 0 :(得分:1)

让您的活动实现OnFragmentInteractionListener,例如,

public class MainActivity extends AppCompatActivity implements  YourFragment.OnFragmentInteractionListener
{
.
.
@Override
public void onFragmentInteraction(Uri uri) {

}
}

在您的活动中实施OnFragmentInteractionListener提供的方法