![](/img/trans.png)
[英]Error inflating class android.fragment.app.FragmentContainerView, can someone tell me what I'm missing
[英]Error inflating class fragment. What can I do here?
前幾天我正在編寫這個程序,希望片段運行良好,但事實並非如此。 我的項目是一個相對布局應用程序,其中 GPS map 將首先出現在屏幕上活動彈出,然后選擇查看印度尼西亞的一些爪哇文化(以網格 - 卡片視圖組合的形式),將可供選擇。
在這里,根據 Logcat,在這一行中,我有一個 class 片段膨脹錯誤:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_java_island); // Erroring line
KerisCard = (CardView) findViewById(R.id.KerisCard);
TradClothesCard = (CardView) findViewById(R.id.TradClothesCard);
TradHouseCard = (CardView) findViewById(R.id.TradHouseCard);
TariMerakCard = (CardView) findViewById(R.id.TariMerakCard);
SupportMapFragment javaMapFragment = (SupportMapFragment) getSupportFragmentManager().
findFragmentById(R.id.java_island_map);
javaMapFragment.getMapAsync(this); . . . }
回想起來,我對片段的概念並不是很熟悉,因為我一直在參加的課程對片段的使用沒有太詳細的說明。 另外,我必須注意,如果沒有聲明 object 引用(onCreate() 函數上的 (CardView) 聲明),則不會出現此錯誤,並且該應用程序將正常執行。
而不是支持片段引用直接創建片段引用並從片段調用方法。 SampleFragment fragment=new SampleFragment() Fragment.someMethod 這里有一個困惑你想在activity中打開fragment嗎? 因為您正在嘗試從 id 中查找片段,所以您是否在 xml 中創建了如果沒有,那么就有問題了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.