【发布时间】:2015-06-10 07:20:06
【问题描述】:
如果这是一个愚蠢的错误,请原谅我。我的活动布局 (xml) 中有两个片段,为了让它们进行交流,我试图在我的主要活动中获取一个片段的实例。我之前做过,但这次它抛出错误(需要视频列表片段但找到片段)我不确定我给出了什么错误。可能只是一个愚蠢的错误。你能帮忙吗?提前致谢。
下面是sn-p代码:
public class VideoListingActivity extends ActionBarActivity implements FilterFragment.OnFilterItemSelectedListener{
public VideoListFragment videoListFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_listing);
videoListFragment =(VideoListFragment) getSupportFragmentManager().findFragmentById(R.id.frg_video_listing_video_listing_fragment);
}
下面是布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="my activity context">
<fragment
android:layout_width="match_parent"
android:layout_height="@dimen/filter_fragment_height"
android:name="com.text1.text2.text3.pkg.FilterFragment"
android:id="@+id/frg_video_listing_filter_fragment"
></fragment>
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.text1.text2.text3.pkg.VideoListFragment"
android:id="@+id/frg_video_listing_video_listing_fragment"
></fragment>
</RelativeLayout>
下面是片段类代码
package com.rrdtech.vidyavaan.android.Fragments;
import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.rrdtech.vidyavaan.android.R;
public class VideoListFragment extends ListFragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.video_list_fragment,container,false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
}
}
下面是堆栈跟踪
Error:(22, 91) error: inconvertible types
required: VideoListFragment
found: Fragment
【问题讨论】:
-
能否展示片段类代码?
-
能否提供引发异常的堆栈跟踪?
-
堆栈跟踪以及导致异常的哪一行(我猜我知道是哪一行)会有所帮助!
-
导致问题的行是 ************* videoListFragment =(VideoListFragment) getSupportFragmentManager().findFragmentById(R.id.frg_video_listing_video_listing_fragment); *********** 在我持有碎片的活动中
标签: android android-fragments fragmentmanager