在我添加代码来更改背景颜色之前,该应用程序运行良好,因此它必须在那里,但我对 java 和 Android Studio 非常陌生,所以我不确定是什么。
该应用程序编译良好,但一旦我单击按钮就会中断。中断我的意思是它在 AVD 上关闭,我收到一个对话框,说应用程序已停止。如果可以的话请帮忙。
package com.example.jacqueline.funfacts;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FunFactsActivity extends AppCompatActivity {
private FactBook factbook = new FactBook();
private ColorChange colorChange = new ColorChange();
//Declare our view variables
private TextView factTextView;
public Button showFactButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
//Assign the views from the layout file to the corresponding variables
factTextView = findViewById(R.id.factTextView);
showFactButton = findViewById(R.id.showFactButton);
View.OnClickListener factListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//Get a fact from our FactBook
String fact = factbook.getFact();
//Update the screen with our new fact
factTextView.setText(fact);
//Change the background color
colorChange.setColor();
}
};
showFactButton.setOnClickListener(factListener);
}
}
拉丁的传说
BIG阳
相关分类