更改方向时片段选项卡崩溃

时间:2015-07-12 20:00:38

标签: android android-fragments

错误讯息:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.basket/com.example.basket.MainActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.basket.MainActivity$TabContentFragment: make sure class name exists, is public, and has an empty constructor that is public

片段类:

public class TabContentFragment extends Fragment {
    public TabContentFragment()
    {

    }
    private String mText;
    public TabContentFragment(String text) {
        mText = text;
    }
    public String getText() {
        return mText;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {      
        View fragView = inflater.inflate(R.layout.action_bar_tab_content,                  container, false);                     
        mlistView= (ListView) fragView.findViewById(R.id.postListView); 
        getData(mText);
        return fragView;
    }

}

1 个答案:

答案 0 :(得分:0)

该片段是内部类吗?如果是这样,您将需要使该内部类静态。

见这里: Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public