帮我看下程序,点击后直接崩溃,原因是啥?
package com.example.homework2019;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.example.homework2019.model.Book;
import com.example.homework2019.model.Person;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private EditText mNameEditText;
private RadioGroup mSexRadioGroup;
//private RadioButton mMaleRadioButton;
// private RadioButton mFemaleRadioButton;
private EditText mTimeEditText;
private CheckBox mHisCheckBox;
private CheckBox mSusCheckBox;
private CheckBox mArtCheckBox;
private SeekBar mSeekBar;
private ImageView mBookImageView;
private Button mSeekButton;
private Button mNextButton;
private Person mPerson;
private List<Book> Books;
// private List<Book> BookResult;
private boolean misArt;
private boolean misHis;
private boolean misSus;
private int seekAge;
private int bookResultIndex;
private int mCurrentIndex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findviews();//初始化控件
intdata();//初始化数据
setListeners();//为控件添加监听器实现基本功能
//自测
}
private void intdata(){
//创建书籍集合并初始化数据
List<Book> Books = new ArrayList<>();
Books.add(new Book("人生感悟","文艺",25,false,false,true,R.drawable.aa));
Books.add(new Book("边城","文艺",25,false,false,true,R.drawable.bb));
Books.add(new Book("sapir","悬疑",35,false,true,false,R.drawable.cc));
Books.add(new Book("光辉岁月","历史",35,true,false,false,R.drawable.dd));
Books.add(new Book("宋词三百首","文艺",18,false,false,true,R.drawable.ee));
Books.add(new Book("一个粉色帽","悬疑",28,false,true,false,R.drawable.f));
Books.add(new Book("中国古代文学","文艺",27,false,false,true,R.drawable.ff));
Books.add(new Book("无花果","文艺",30,false,false,true,R.drawable.gg));
Books.add(new Book("古镇记忆","历史",18,false,false,true,R.drawable.hh));
}
private void findviews(){
mNameEditText = (EditText) findViewById(R.id.nameEditText);
mSexRadioGroup = (RadioGroup) findViewById(R.id.sexRadioGroup);
// mMaleRadioButton = (RadioButton) findViewById(R.id.maleRadioButton);
// mFemaleRadioButton = (RadioButton) findViewById(R.id.femaleRadioButton);
mTimeEditText = (EditText) findViewById(R.id.timeEditText);
mHisCheckBox = (CheckBox) findViewById(R.id.hisCheckBox);
mSusCheckBox = (CheckBox) findViewById(R.id.susCheckBox);
mArtCheckBox = (CheckBox) findViewById(R.id.artCheckBox);
mSeekBar = (SeekBar) findViewById(R.id.seekBar);
mSeekBar.setProgress(10);
mBookImageView = (ImageView) findViewById(R.id.bookImageView);
mSeekButton = (Button) findViewById(R.id.seekButton);
mNextButton = (Button) findViewById(R.id.nextButton);
}
Person Person=new Person();
List<Book> BookResult = new ArrayList<>();
//为选书者获取性别数据
private void setListeners() {
mSexRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) {
case R.id.maleRadioButton:
mPerson.setPersonsex("男");
break;
case R.id.femaleRadioButton:
mPerson.setPersonsex("女");
break;
}
}
});
//复选框尽行书籍归类
mArtCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
misArt=b;
}
});
mHisCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
misHis =b;
}
});
mSusCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
misSus =b;
}
});
//seekbar对于用户的年龄进行数据采集
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
seekAge = seekBar.getProgress();
}
});
mSeekButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
search();
}
});
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
private int search() {
//结果列表每次都清空
//遍历所有菜
//如果符合条件就加入到我们的结果列表中
if(BookResult == null){
BookResult = new ArrayList<>();
}
BookResult.clear();//如果不为空则清空列表
bookResultIndex=0;
for (int index = 0; index < Books.size(); index++){
Book book=Books.get(index);
if(book != null){//如果此本书不为空
// 价格要小于设定的价格
// 是顾客选择的口味
if(book.getAge() > seekAge &&
(book.isArt() == misArt
|| book.isHistory() == misHis
|| book.isSus() == misSus)
){
BookResult.add(book);
}
}
}
mCurrentIndex=0;
return mCurrentIndex;
}
private int see() {
if (mCurrentIndex < BookResult.size()) {
mBookImageView.setImageResource(BookResult.get(mCurrentIndex).getPic());
} else {
mBookImageView.setImageResource(R.drawable.ic_launcher_foreground);
}
mCurrentIndex++;
return mCurrentIndex;
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 1789 份
- 解答问题 2907 个
Android大楼Java起,本阶段是Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始入门Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星