Solution 1 :
I fixed it my own, the problem was that I had this line after the onClickListeners:
setContentView(R.layout.activity_main);
But this line hast to be right at the top of the OnCreate
Solution 2 :
You can click on it and press option + Enter
. The IDE will tell you it can be replace with lambda
it can make the code more clear
Problem :
the onClickListener of my FloatingActionButton and Toolbar Icon are not working.
Here is the code:
floatingActionButton = findViewById(R.id.pausebutton);
floatingActionButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EventHandlerClass.releaseMediaPlayer();
}
});
search_ico=findViewById(R.id.search_ico);
search_ico.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this,searchActivity.class));
}
});
It is weird because the “new OnClickListener()” is greyed out like this:
My clicks are going through the FloatingActionButton, here is the code:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center|bottom"
android_layout_marginBottom="60dp"
android_src="@drawable/paused"
app_fabSize="normal"
app_backgroundTint="#38464E"
app_elevation="20dp"
android_id="@+id/pausebutton"/>
I have absolutely no Idea what is wrong, looks right to me.
Does anyone have some Ideas what I could try?
Comments
Comment posted by stackoverflow.com/questions/9577338/…
In this example the user explicitly casts the findViewById as a Button. Does that help you at all?
Comment posted by EveRegalado
I remember that rarely, when copying and pasting between files from other android projects, the project did not compile … the code was correct, there were no code errors … until I saw that I had not placed or deleted the line “setContentView (R.layout.activity_main);” during copy and paste… Good luck in your project
Comment posted by Aaron Waller
This isn’t solving the problem, I still can’t click the FloatingActionButton