0

所以我正在添加一个可扩展的晶圆厂,但我遇到了这个错误,我不明白为什么......

这是日志中的确切错误:

ava.lang.ClassCastException:com.nambimobile.widgets.efab.ExpandableFabLayout 无法在 CategoryActivity.onCreate(CategoryActivity.java:56)中转换为 com.nambimobile.widgets.efab.ExpandableFab

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;




public class CategoryActivity extends AppCompatActivity implements CategoryAdapter.onCategoryClickListener {

    public static final String CATEGORY_NAME = "category_name";

    private NoteViewModel noteViewModel;
    private CategoryAdapter adapter;
    private RecyclerView recyclerView;
    private List<FolderWithNotes> folderWithNotes;
    private Note note;
    private Folder folder;


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

       noteViewModel = new ViewModelProvider.AndroidViewModelFactory(this.getApplication()).create(NoteViewModel.class);

        recyclerView = findViewById(R.id.category_recyclerview);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        noteViewModel.getFolderWithNotes().observe(this, folderWithNotes -> {


       });

        ExpandableFab exFab =  findViewById(R.id.exFab);
        exFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case (R.id.exfab_add_category):
                        Intent intent = new Intent(CategoryActivity.this, AddCategoryActivity.class);
                        startActivity(intent);

                    case (R.id.exfab_delete_category):
                    default:
                        break;

                }


            }

        });



        ActivityResultLauncher<Intent> launcher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> {

            if(result.getResultCode() == Activity.RESULT_OK) {
                Intent data = result.getData();
                String category = data.getStringExtra(AddCategoryActivity.CATEGORY_REPLY);
                String notes = data.getStringExtra(AddNoteActivity.NOTE_REPLY);

                Folder folder = new Folder(note.getFolder_name());
                noteViewModel.insert(folder, note);

            }


        });

    }


    @Override
    protected void onResume() {
        super.onResume();

        adapter = new CategoryAdapter(folderWithNotes, this, this);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onCategoryClick(int position) {

        // code to transfer to AddNoteActivity (where the note list is) by clicking the category folder
        noteViewModel.getFolderWithNotes().observe(this, folderWithNotes -> {
            Intent intent = new Intent(CategoryActivity.this, NotesActivity.class);
            intent.putExtra(CATEGORY_NAME, folderWithNotes.get(position).getFolder().getFolderName());

        });


    }
    public void addCategoryClicked(View view) {
        EditText editCategory = findViewById(R.id.et_add_category);
        String categoryTitle = editCategory.getText().toString().trim();
        Intent intent = new Intent(CategoryActivity.this, AddCategoryActivity.class);


    }

    public void deleteCategoryClicked(View view) {
    }

//    @Override
//    public void addCategoryClicked(int position) {
//
//    }
//
}
4

0 回答 0