在我输入每门课程的学分和成绩后,然后按下计算 GPA 按钮,我的应用程序就崩溃了。
我尝试过调试,发现所有逻辑都运行良好,直到为我的 textview 设置文本。然后它崩溃并且不显示按钮下方的 GPA。
package com.example.gpa_tejadaa4_calculator;
import android.support.v7.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 {
private EditText ch1,ch2,ch3,ch4,ch5;
private EditText g1,g2,g3,g4,g5;
private Button gpa_calc;
private TextView result;
//private int credit_sum = 0;
//private int grade_sum = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Credit Hours
ch1 = (EditText)findViewById(R.id.C_H1);
ch2 = (EditText)findViewById(R.id.C_H2);
ch3 = (EditText)findViewById(R.id.C_H3);
ch4 = (EditText)findViewById(R.id.C_H4);
ch5 = (EditText)findViewById(R.id.C_H5);
//Grades
g1= (EditText)findViewById(R.id.L_G1);
g2= (EditText)findViewById(R.id.L_G2);
g3= (EditText)findViewById(R.id.L_G3);
g4= (EditText)findViewById(R.id.L_G4);
g5= (EditText)findViewById(R.id.L_G5);
//Button
gpa_calc = (Button) findViewById(R.id.button);
//Result
result = (TextView)findViewById(R.id.result);
gpa_calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculateGPA();
}
});
}
public void calculateGPA() {
double quality_points = 0;
double credit_sum = 0;
double gpa=0;
double chour1 = Double.valueOf(ch1.getText().toString());
double chour2 = Double.valueOf(ch2.getText().toString());
double chour3 = Double.valueOf(ch3.getText().toString());
double chour4 = Double.valueOf(ch4.getText().toString());
神不在的星期二
吃鸡游戏
相关分类