我得到错误"方法不会覆盖其超类"

时间:2018-05-28 15:35:16

标签: android override

我收到此错误。我该如何解决?

  

方法不会覆盖其超类

我试着做一切,但我无法完成。任何帮助将不胜感激。

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private DatabaseReference mDatabase;
    private FirebaseRecyclerAdapter<App, CarsViewHolder> mAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mDatabase = FirebaseDatabase.getInstance().getReference().child("data");
        mDatabase.keepSynced(true);
        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        mRecyclerView.setAdapter(mAdapter);

        DatabaseReference personsRef = FirebaseDatabase.getInstance().getReference().child("data");
        Query personsQuery = personsRef.orderByKey();


        mRecyclerView.hasFixedSize();
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        FirebaseRecyclerOptions recyclerOptions = new FirebaseRecyclerOptions.Builder<App>().setQuery(personsQuery, App.class).build();

        mRecyclerView = new RecyclerView(recyclerOptions) {
            @NonNull
            @Override // error in here
            public App onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.recycler_view_layout, parent, false);
                return new App(view);
            }

            @Override // error in here
            protected void onBindViewHolder(@NonNull App holder, int position, @NonNull App model) {
                holder.setImg(model.getImg());
                holder.setManufac(model.getManufac());
                holder.setModel(model.getModel());
                holder.setPrice(model.getPrice());
            }
        };
    }

    @Override
    public void onStart() {
        super.onStart();
        mAdapter.startListening();
    }

    @Override
    public void onStop() {
        super.onStop();
        mAdapter.stopListening();


    }


}

1 个答案:

答案 0 :(得分:0)

这里有一些奇怪的代码

public App onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

在这里

protected void onBindViewHolder(@NonNull App holder, int position, @NonNull App model) {

而不是App尝试使用RecyclerView.ViewHolder并删除@NonNull App model参数

您应该创建扩展ViewHolder的自定义RecyclerView.ViewHolder类。见这里的例子 https://developer.android.com/guide/topics/ui/layout/recyclerview#java