每次我向TextViews添加功能时,应用程序都会崩溃

时间:2018-06-10 19:48:15

标签: android android-layout android-studio

1.这是我的MainActivity.java 2.没有得分.setText()一切都很好

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText score = (EditText) findViewById(R.id.editText);
public void buttonfunc(View view){
 Toast.makeText(MainActivity.this, "HOPE", Toast.LENGTH_SHORT).show();
score.setText("hey");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

0 个答案:

没有答案