แท็บส่วนย่อยล้มเหลวเมื่อเปลี่ยนการวางแนว

ข้อความผิดพลาด:

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;
    }

}

person user1445018    schedule 12.07.2015    source แหล่งที่มา


คำตอบ (1)


ชิ้นส่วนนั้นเป็นคลาสภายในหรือไม่? หากเป็นเช่นนั้น คุณจะต้องทำให้คลาสภายในนั้นคงที่

ดูที่นี่: ไม่สามารถ เพื่อสร้างอินสแตนซ์แฟรกเมนต์ตรวจสอบให้แน่ใจว่ามีชื่อคลาสอยู่ เป็นสาธารณะ และมีตัวสร้างว่างที่เป็นสาธารณะ

person lostintranslation    schedule 12.07.2015