Implementing recycler view using sugar ORM

i am trying to display data from a textview on an activity onto a recycler view on a fragment. I have an adapter class to implement the adapter methods. however when i click the fragment the app closes and the .count method remains unable to be resolved. the code is attached below;

    package com.example.afa.geobuddy;
    public class NotesFragment extends Fragment {

    long notecount;
    int modifyposition = -1;
    NotesDbAdapter notesDbAdapter;
    List<Note> notes = new ArrayList<>();

    public void onCreate(Bundle savedInstanceState) {


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View noteview = inflater.inflate(R.layout.fragment_notes, container, false);
        Toolbar ntoolbar = (Toolbar) noteview.findViewById(;
        FloatingActionButton note_fab = (FloatingActionButton) noteview.findViewById(;
        note_fab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), AddNote.class));
        RecyclerView recyclerView = (RecyclerView) noteview.findViewById(;
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
       // notesDbAdapter = new NotesDbAdapter(getActivity(),notes);
     //   recyclerView.setAdapter(notesDbAdapter);

        notecount = Note.count(Note.class);
            notes = Note.listAll(Note.class);
             notesDbAdapter = new NotesDbAdapter(getActivity(),notes);

        return noteview;


StackTrcae enter image description here

1 answer

  • answered 2018-02-13 01:58 Levi Moreira

    Please check if you're correctly importing the Note class. Moreover, you can try to get the count using the SugarRecord class, i find it to work better than using the normal classes.

    noteocunt = SugarRecord.count(Note.class);

    Please check if you're using the most recent version of the library. Whenever you update your schema, please update (increase) your DB version in your manifest file.

    <meta-data android:name="VERSION" android:value="2" />