我是 Android 编程新手,但对 Java 有一点经验。但是,我正在创建一个 Android 应用程序,当用户单击一个按钮时,我希望实例化一个不同的类......这是我的MainActivity.java
private void setButtonClickListener() {
Button budgetPeriodButton = (Button)findViewById(R.id.budgetPeriodButton);
Button incomingsButton = (Button)findViewById(R.id.incomingsButton);
Button outgoingsButton = (Button)findViewById(R.id.outgoingsButton);
Button resultsButton = (Button)findViewById(R.id.resultsButton);
budgetPeriodButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
BudgetPeriod bp = new BudgetPeriod();
bp.changeUI();
}
这是 BudgetPeriod 类
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
public class BudgetPeriod extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_budget);
super.onCreate(savedInstanceState);
changeUI();
}
public void changeUI() {
ImageView imageView = (ImageView) findViewById(R.id.budget_icon);
Drawable newBudgetImage;
newBudgetImage = getResources().getDrawable(R.drawable.budget_period);
imageView.setImageDrawable(newBudgetImage);
}
}
如果用户单击该按钮,则模拟器上的错误消息会显示“不幸的是,此应用程序必须关闭”
关于我做错了什么的任何想法?谢谢