我创建了一个包含许多列表片段的应用程序。它工作得很好。我有一个主应用程序,我想在其中合并新的列表片段应用程序。我也在 Android 清单中包含了活动。下面是我的 ListFragment App 的主要活动,xml 有三个片段,没有别的。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ctx1 = getApplicationContext();
}
在我的主应用程序中,我有几个按钮,它们在点击时启动不同的活动。
如何使用其中一个按钮启动我的列表片段。
我确实使用过:
Intent listactivity= new Intent(MainActivity.this, TestListFragmentMain.class);
startActivity(listactivity);
但是上面的代码给了我一些膨胀的异常:(有没有简单的方法可以做到这一点?请回复
跟踪日志:
D/dalvikvm( 1478): GC_CONCURRENT freed 140K, 14% free 7493K/8707K, paused 13ms+0ms, total 76ms
D/AndroidRuntime( 1478): Shutting down VM
W/dalvikvm( 1478): threadid=1: thread exiting with uncaught exception (group=0xa631d288)
E/AndroidRuntime( 1478): FATAL EXCEPTION: main
E/AndroidRuntime( 1478): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.droidtv.TvPlayerFunctionalTestApp/org.droidtv.TvPlayerFunctionalTestApp.AndroidListFragmentActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime( 1478): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
E/AndroidRuntime( 1478): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 1478): at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 1478): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 1478): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1478): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1478): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 1478): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1478): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1478): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 1478): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 1478): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1478): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime( 1478): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 1478): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
E/AndroidRuntime( 1478): at android.app.Activity.setContentView(Activity.java:1952)
E/AndroidRuntime( 1478): at org.droidtv.TvPlayerFunctionalTestApp.AndroidListFragmentActivity.onCreate(AndroidListFragmentActivity.java:18)
E/AndroidRuntime( 1478): at android.app.Activity.performCreate(Activity.java:5098)
E/AndroidRuntime( 1478): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime( 1478): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime( 1478): ... 11 more
E/AndroidRuntime( 1478): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment org.droidtv.VideoFeaturingTestApp.VideoFeaturingMainMenuClass: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime( 1478): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
E/AndroidRuntime( 1478): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime( 1478): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)