I got the following:
public class activity_menuPrincipal extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_menu_principal);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
public void abrirCalculadora(View v){
Intent openCalculadora=new Intent(this,MainActivity.class);
startActivity(openCalculadora);
}
}
}
The line 25, public void abrirCalculadora(View v){
is not working, specifically “View” is always red, and I don’t know why. All the errors mention “‘;’ expected”, “‘)’ expected” and “public illegal start of expression”. Yes, View is already imported.
I have had problems with my computer, but I don’t think that the reason behind that.
Manuel Lermanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
All classes that aren’t stock Java/Kotlin classes need an explicit import declaration at the top of the source file. (Either on the class directly or on the package
Hover over the View
declaration that is highlighted in red. The pop-up dialog will offer you a link to “import class”. Click it.
This will add an import android.view.View;
statement to the top of your source file.
Repeat the same thing for the Intent
class as well.
4
I realised I was writing where I didn’t have to (inside the protected void onCreate
). Here’s the corrected version:
public class activity_menuPrincipal extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_menu_principal);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
*public void abrirCalculadora(View v){
Intent openCalculadora = new Intent(this, MainActivity.class);
startActivity(openCalculadora);*
}
}
Manuel Lermanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.