这是我第一次使用与我一样的碎片。 我真心实意地理解我需要做些什么才能正确显示名单,因为从现在起,我选择我的节目中的表格时没有任何显示。 目前,我正经历一个错误。
11-17 16:18:59.410: E/AndroidRuntime(18219): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tyczj.bowling/com.tyczj.bowling.Tabs}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.tyczj.bowling.BowlersList$BowlersListFragment: make sure class name exists, is public, and has an empty constructor that is public
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.os.Handler.dispatchMessage(Handler.java:99)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.os.Looper.loop(Looper.java:132)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.ActivityThread.main(ActivityThread.java:4028)
11-17 16:18:59.410: E/AndroidRuntime(18219): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 16:18:59.410: E/AndroidRuntime(18219): at java.lang.reflect.Method.invoke(Method.java:491)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-17 16:18:59.410: E/AndroidRuntime(18219): at dalvik.system.NativeStart.main(Native Method)
11-17 16:18:59.410: E/AndroidRuntime(18219): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.tyczj.bowling.BowlersList$BowlersListFragment: make sure class name exists, is public, and has an empty constructor that is public
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.Fragment.instantiate(Fragment.java:504)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.tyczj.bowling.Tabs$TabListener.onTabSelected(Tabs.java:110)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:483)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.android.internal.app.ActionBarImpl.setSelectedNavigationItem(ActionBarImpl.java:303)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.android.internal.app.ActionBarImpl.setNavigationMode(ActionBarImpl.java:883)
11-17 16:18:59.410: E/AndroidRuntime(18219): at com.tyczj.bowling.Tabs.onCreate(Tabs.java:25)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
11-17 16:18:59.410: E/AndroidRuntime(18219): ... 11 more
11-17 16:18:59.410: E/AndroidRuntime(18219): Caused by: java.lang.InstantiationException: com.tyczj.bowling.BowlersList$BowlersListFragment
11-17 16:18:59.410: E/AndroidRuntime(18219): at java.lang.Class.newInstanceImpl(Native Method)
11-17 16:18:59.410: E/AndroidRuntime(18219): at java.lang.Class.newInstance(Class.java:1301)
11-17 16:18:59.410: E/AndroidRuntime(18219): at android.app.Fragment.instantiate(Fragment.java:493)
这是我xml的一部分。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout android:layout_width="400dp"
android:layout_height="match_parent">
<fragment android:name="com.tyczj.bowling.BowlersList"
android:id="@+id/bListFrag"
android:layout_height="match_parent"
android:layout_width="400dp"/>
</LinearLayout>
</LinearLayout>
这是我的清单
public class BowlersList extends ListFragment {
@Override
public void onCreate(Bundle state){
super.onCreate(state);
if(getFragmentManager().findFragmentById(R.id.bListFrag)==null){
BowlersListFragment list = new BowlersListFragment();
getFragmentManager().beginTransaction().add(R.id.bListFrag, list).commit();
}
}
public class BowlersListFragment extends Fragment {
static public final String STATE_CHECKED="com.tyczj.bowling.STATE_CHECKED";
@Override
public void onActivityCreated(Bundle state){
super.onActivityCreated(state);
BowlersDB db = new BowlersDB(BowlersList.this);
db.open();
Cursor c = db.getBowlers();
startManagingCursor(c);
String[] names = new String[c.getCount()];
if(c != null && c.moveToFirst()){
int i = 0;
do{
names[i] = c.getString(c.getColumnIndex(BowlersDB.NAME));
i++;
}while(c.moveToNext());
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bowlers, container, false);
return v;
}
}