为什么当我从String转换为int时出现错误,但我认为转换是正确的。但我知道错误是什么 这是代码:
bhstudentgrouplist.count() = 0
错误消息:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText weight;
EditText age;
Button result;
TextView txtresult;
String w;
String a;
double r1;
int w1;
int a1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
weight=findViewById(R.id.w);
age=findViewById(R.id.a);
result=findViewById(R.id.btnresult);
txtresult=findViewById(R.id.txtresult);
w= weight.getText().toString();
w1=Integer.parseInt(w);
a= age.getText().toString();
a1=Integer.parseInt(a);
r1=w1/2.2*a1/28.3/8;
result.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
txtresult.setText("number of cups :"+r1);
}
});
}
}