强制关闭:确保类名存在,是公共的,并且具有在片段视图寻呼机中公共的空构造函数

时间:2015-12-16 08:44:20

标签: android android-fragments background

我面临以下问题 当我运行我的应用程序时,它正常工作,但是当我点击主页按钮并且我的应用程序在后台运行时,过了一段时间我重新打开应用程序它已经取消了这个通知:

Make sure class name exists, is public, and has an empty constructor that is public.

我试过这段代码:

@SuppressLint("ValidFragment")
public class TabHomeFragment extends Fragment implements ObservableScrollViewCallbacks,
        InteractiveScrollView.OnScroll, InteractiveScrollView.OnBottomReachedListener,
        InteractiveScrollView.OnTopReachedListener, SwipeRefreshLayout.OnRefreshListener {

    private String s;
    private ArrayList<Post> arrData;
    private ArrayList<Post> arrDatanew = new ArrayList<Post>();
    private HomeAdapter adapter;
    private ListAdapter listAdapter;
    private ArrayList<String> listPostMarked = new ArrayList<>();
    RelativeLayout header;
    ObservableListView lv;
    int checkPage;
    Boolean isMenuHide = false;
    InteractiveScrollView scrollview;
    private ArrayList<Post> listArray = new ArrayList<>();
    ImageView ivUp;
    ObservableScrollViewCallbacks scrollBack;
    View footer;
    ImageView imgLoad;
    private String tableName;

    public TabHomeFragment() {
        super();
    }

    public TabHomeFragment(String s, ArrayList<Post> arrData, ArrayList<Post> listArray,
                           String tableName, ObservableScrollViewCallbacks scrollBack) {
        this.s = s;
        this.arrData = arrData;
        this.listArray = listArray;
        this.tableName = tableName;
        this.scrollBack = scrollBack;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d("LOGTAG", "On Create Home ");
        View view;
        view = inflater.inflate(R.layout.home_gridview_layout, container, false);
       return view;
}

但它没有运行 怎么办呢?

请帮帮我。

1 个答案:

答案 0 :(得分:0)

删除您声明的空构造函数或super()

public TabHomeFragment() {
        super();
    }

使用界面如下

任何应该将数据传递回其包含活动的片段都应该声明一个接口来处理和传递数据。然后确保包含的活动实现了这些接口。例如:

在你的片段中,声明接口......

public interface OnDataPass {
    public void onDataPass(String data);
}

然后,连接包含的类&#39;在onAttach方法中实现片段的接口,如下所示:

OnDataPass dataPasser;

@Override
public void onAttach(Activity a) {
    super.onAttach(a);
    dataPasser = (OnDataPass) a;
}

在你的片段中,当你需要处理数据传递时,只需在dataPasser对象上调用它:

public void passData(String data) {
    dataPasser.onDataPass(data);
}

最后,在实现OnDataPass ...的包含活动中

@Override
public void onDataPass(String data) {
    Log.d("LOG","hello " + data);
}