Why is the class expected error?

Asked

Viewed 79 times

0

I am programming in Java in Android Studio and there is an error .class expected:

package com.example.equacaodosegundograu;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView txt1, txt2, txt3, total;
    EditText edittext2, edittext3;
    Button calc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txt1 = (TextView) findViewById(R.id.txt1);
        txt2 = (TextView) findViewById(R.id.txt2);
        txt3 = (TextView) findViewById(R.id.txt3);
        total = (TextView) findViewById(R.id.total);
        edittext2 = (EditText) findViewById(R.id.edittext2);
        edittext3 = (EditText) findViewById(R.id.edittext3);
        calc = (Button) findViewById(R.id.calc);
        calc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                float M = float.parseFloat;
                float V = float.parseFloat(edittext3.getText().toString());
                float ec = (M * (V * V)) / 2;
                total.setText(Float.toString(ec));
            }
        })

    ;}
}

imagem de onde ocorre o erro

todos os erros

1 answer

3

float is a primitive type, has no methods.

Methods belong to classes, hence the error .class expected.

The method parseFloat() belongs to the class Float.

Alter

float V = float.parseFloat(edittext3.getText().toString());

for

float V = Float.parseFloat(edittext3.getText().toString());

Do not forget to check/ensure that the contents of edittext3 represent a float.

When naming variables use meaningful names.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.