2012-10-30 70 views
0

我有一個intent的問題,它擴展了Fragment,它來自一個擴展了Activity的類。如何從擴展Activity的類開始擴展片段的意圖?

TabBar2.class - >擴展活動

Favourite.class - >擴展片段

這是我寫我的意圖。

Intent intent1 = new Intent(TabBar2.this, Favourite.class); 
startActivity(intent1); 

但我的應用程序崩潰時,我運行的意圖onClick。 我的logCat說

Unable to instantiate activity 
ComponentInfo{com.honey.test/com.honey.test.Favourite}: 
java.lang.ClassCastException: com.honey.test.Favourite 

我做錯了什麼?有人可以指導我如何解決這個問題嗎?

+0

檢查THI一個'HTTP:// stackoverflow.com /問題/ 9831728 /啓動一個片段的通路意向中之fragment' – Steve

回答

9

這是因爲你不能把通過意向片段,片段是FragmentActivity

總而言之片段的一部分內容沒有容器,所以你需要創建一個FragmentActivity並添加片段(收藏)在這,然後調用

Intent intent1 = new Intent(TabBar2.this, SomeFragmentActivity.class); 
startActivity(intent1); 

A Fragment is a piece of an application's user interface or behavior that can be placed in an Activitymore information

+0

謝謝你這對我來說很明顯。 :) –

+0

@hotveryspicy尼斯答案和說明++ –

+0

詳細描述我dint得到。 – 2014-11-07 06:01:14