Agora estou com outro erro quando eu click no adicionar provas, da um erro.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.alura.roomapplication, PID: 19451
java.lang.RuntimeException: Expecting menu, got android.support.design.widget.CoordinatorLayout
at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:159)
at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:126)
at br.com.alura.roomapplication.fragments.ListaProvasFragment.onCreateOptionsMenu(ListaProvasFragment.java:46) <-- aqui a linha do erro
o codigo da class listaprovasfragment
public class ListaProvasFragment extends Fragment {
private provasDelegate delegate;
private ListView listagem;
private FloatingActionButton cadastrar;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
delegate = (provasDelegate) getActivity();
setHasOptionsMenu(true);
}
@SuppressLint("ResourceType")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.layout.fragment_lista_provas, menu);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_lista_provas, container, false);
configuraCampos(view);
return view;
}
private void configuraCampos(View view) {
configuraListagem(view);
cadastrar = view.findViewById(R.id.fragment_lista_provas_fab);
listenerPara(cadastrar);
}
private void configuraListagem(View view) {
listagem = view.findViewById(R.id.fragment_lista_provas);
Context contexto = getContext();
Gerador_BD gerador_bd = new Gerador_BD();
AlunoDatabase database = gerador_bd.gera(contexto);
final ProvaDao provaDao = database.getProvaDao();
List<Prova> provas = provaDao.busca();
final ArrayAdapter<Prova> adapter = configuraAdapter(contexto, provas);
listagem.setOnItemClickListener(clickNaLista());
}
@NonNull
private ArrayAdapter<Prova> configuraAdapter(Context contexto, List<Prova> provas) {
final ArrayAdapter<Prova> adapter = new ArrayAdapter<>(contexto, android.R.layout.simple_list_item_1, provas);
listagem.setAdapter(adapter);
return adapter;
}
private AdapterView.OnItemClickListener clickNaLista() {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int posicao, long id) {
Prova prova = (Prova) adapterView.getItemAtPosition(posicao);
delegate.lidaCom(prova);
}
};
}
private void listenerPara(FloatingActionButton botaoFlutuante) {
botaoFlutuante.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
delegate.lidaComClickDoFAB();
}
});
}
@Override
public void onResume() {
super.onResume();
delegate.alteraNomeActionBar("Provas realizadas");
}