AS重启以后报错了,上次是删除project再重建就好了,现在不行了
来源:3-2 项目作业
荒野56
2020-10-15 01:33:57
# 具体遇到的问题
写的代码 按钮按上去没用,然后AS重启了以后就报错了,折腾了两三个小时还是没用,依然错
# 报错信息的截图
Could not load wrapper properties from 'D:\MyApplication\gradle\wrapper\gradle-wrapper.properties'.
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
老师帮我看看代码哪里有问题吧
<?xml version="1.0" encoding="UTF-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout tools:context=".MainActivity" android:background="#ff99ff" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
-<LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" android:layout_margin="10dp">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_margin="5dp" android:typeface="monospace" android:textStyle="bold|italic" android:textSize="30sp" android:textColor="#ff0000" android:text="@string/borrowBook" android:gravity="center_horizontal"/>
-<LinearLayout android:layout_height="45dp" android:layout_width="match_parent" android:orientation="horizontal">
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="@string/reader" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
<EditText android:layout_height="match_parent" android:layout_width="0dp" android:hint="@string/edit_text_input_hint_name" android:layout_weight="1" android:id="@+id/readerEditText"/>
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="@string/sex" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
-<RadioGroup android:layout_height="match_parent" android:layout_width="wrap_content" android:orientation="horizontal" android:layout_marginRight="10dp" android:id="@+id/sexRadioGroup">
<RadioButton android:layout_height="wrap_content" android:layout_width="50dp" android:text="@string/male" android:id="@+id/male_RadioButton" android:layout_gravity="center_vertical"/>
<RadioButton android:layout_height="wrap_content" android:layout_width="50dp" android:text="@string/female" android:id="@+id/female_RadioButton" android:layout_gravity="center_vertical"/>
</RadioGroup>
</LinearLayout>
-<LinearLayout android:layout_height="45dp" android:layout_width="match_parent" android:orientation="horizontal">
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="@string/lend_time" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
<EditText android:layout_height="match_parent" android:layout_width="0dp" android:hint="@string/edit_text_input_hint_time" android:layout_weight="1" android:id="@+id/lend_timeEditText"/>
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="@string/return_time" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:id="@+id/return_timeTextView"/>
</LinearLayout>
-<LinearLayout android:layout_height="45dp" android:layout_width="match_parent" android:orientation="horizontal">
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="@string/hobby" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
<CheckBox android:layout_height="wrap_content" android:layout_width="100dp" android:textSize="15sp" android:text="@string/history" android:id="@+id/historyCheckBox"/>
<CheckBox android:layout_height="wrap_content" android:layout_width="100dp" android:textSize="15sp" android:text="@string/mystery" android:id="@+id/mysteryCheckBox"/>
<CheckBox android:layout_height="wrap_content" android:layout_width="100dp" android:textSize="15sp" android:text="@string/literature" android:id="@+id/literatureCheckBox"/>
</LinearLayout>
-<LinearLayout android:layout_height="45dp" android:layout_width="match_parent" android:orientation="horizontal">
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="@string/age" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="0" android:gravity="center" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:id="@+id/reader_ageTextView" android:layout_gravity="center"/>
<SeekBar android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:id="@+id/seekBar" android:layout_gravity="center"/>
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:text="100" android:gravity="center_vertical" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
</LinearLayout>
-<LinearLayout android:background="#ffccff" android:layout_height="200dp" android:layout_width="match_parent" android:orientation="horizontal" android:layout_weight="2">
<ImageView android:background="@drawable/f" android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1" android:id="@+id/bookImageView"/>
-<LinearLayout android:layout_height="match_parent" android:layout_width="0dp" android:orientation="vertical" android:layout_weight="1" android:layout_toRightOf="@id/bookImageView">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textSize="20sp" android:text="@string/book_name" android:gravity="center_vertical" android:layout_weight="1" android:id="@+id/bookNameTextView"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textSize="20sp" android:text="@string/book_type" android:gravity="center_vertical" android:layout_weight="1" android:id="@+id/bookTypeTextView"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textSize="20sp" android:text="@string/applicable_age" android:gravity="center_vertical" android:layout_weight="1" android:id="@+id/bookAgeTextView"/>
</LinearLayout>
</LinearLayout>
-<LinearLayout android:layout_height="45dp" android:layout_width="match_parent" android:orientation="horizontal" android:layout_marginTop="10dp">
<Button android:background="#ff00ff" android:layout_height="80dp" android:layout_width="100dp" android:textSize="25sp" android:text="@string/check" android:gravity="center" android:layout_marginLeft="40dp" android:id="@+id/button1" android:layout_gravity="center"/>
<TextView android:layout_height="match_parent" android:layout_width="wrap_content" android:textSize="15sp" android:layout_weight="1" android:id="@+id/resultTextView" android:layout_gravity="center"/>
<Button android:background="#ff00ff" android:layout_height="80dp" android:layout_width="100dp" android:textSize="25sp" android:text="@string/next" android:gravity="center" android:layout_marginRight="40dp" android:id="@+id/button2" android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.testapplication;
import androidx.appcompat.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.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import model.Book;
import model.Reader;
public class MainActivity extends AppCompatActivity {
private EditText readerEditText;
private RadioGroup sexRadioGroup;
private EditText lend_timeEditText;
private CheckBox historyCheckBox;
private CheckBox mysteryCheckBox;
private CheckBox literatureCheckBox;
private TextView reader_ageTextView;
private SeekBar seekBar;
private ImageView bookImageView;
private TextView bookNameTextView;
private TextView bookAgeTextView;
private TextView bookTypeTextView;
private Button button1;
private Button button2;
private Reader reader;
private List<Book> bookResult;
private List<Book> books;
private boolean isHistory;
private boolean isMystery;
private boolean isLiterature;
private int age;
private String age1;
private int cunrrentI;
private TextView resultTextView;
private SimpleDateFormat dateFormat;
private TextView return_timeTextView;
private int num;
private String num1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化控件
findViews();
//初始化数据
initDate();
//为控件添加监听器,实现基本功能
setListeners();
//自测
}
private void initDate() {
//new 一个控的书 List
books = new ArrayList<>();
//初始化添加所有数据
books.add(new Book(R.drawable.aa, "人生感悟","心灵鸡汤",30, false, false, true));
books.add(new Book(R.drawable.bb, "边城","故事",12, true, false, true));
books.add(new Book(R.drawable.cc, "Sapir","传记",18, false, true, true));
books.add(new Book(R.drawable.dd, "光辉岁月","回忆录",16, true, false, true));
books.add(new Book(R.drawable.ee, "宋词三百首","诗文",30, false, false, true));
books.add(new Book(R.drawable.ff, "中国古代文学","文学",14, false, false, true));
books.add(new Book(R.drawable.gg, "无花果","小说",20, false, true, true));
books.add(new Book(R.drawable.hh, "古镇记忆","啥玩意",60, true, true, false));
reader = new Reader();
bookResult = new ArrayList<>();
}
private void findViews() {
readerEditText = findViewById(R.id.readerEditText);
sexRadioGroup = findViewById(R.id.sexRadioGroup);
lend_timeEditText = findViewById(R.id.lend_timeEditText);
return_timeTextView = findViewById(R.id.return_timeTextView);
historyCheckBox = findViewById(R.id.historyCheckBox);
mysteryCheckBox = findViewById(R.id.mysteryCheckBox);
literatureCheckBox = findViewById(R.id.literatureCheckBox);
reader_ageTextView = findViewById(R.id.reader_ageTextView);
seekBar = findViewById(R.id.seekBar);
seekBar.setProgress(0);
bookImageView = findViewById(R.id.bookImageView);
bookNameTextView = findViewById(R.id.bookNameTextView);
bookAgeTextView = findViewById(R.id.bookAgeTextView);
bookTypeTextView = findViewById(R.id.bookTypeTextView);
button1 = findViewById(R.id.button1);
button2 = findViewById(R.id.button2);
resultTextView = findViewById(R.id.resultTextView);
}
private void setListeners() {
//设置单选框Listener
sexRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.male_RadioButton:
reader.setSex("男");
break;
case R.id.female_RadioButton:
reader.setSex("女");
break;
}
}
});
////设置复选框Listener
historyCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isHistory = isChecked;
}
});
mysteryCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isMystery = isChecked;
}
});
literatureCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isLiterature = isChecked;
}
});
//设置seekBar
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
age = seekBar.getProgress();
age1 = String.valueOf(age);
reader_ageTextView.setText(age1);
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
Date date2 = null;
try {
date=(Date) sdf.parse(lend_timeEditText.getText().toString());
date2=(Date) sdf.parse(return_timeTextView.getText().toString());
if(date.after(date2)){
finish();
Toast.makeText(MainActivity.this,"借书时间晚于还书时间,退出",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this,"Person[name="+readerEditText.getText().toString()+",sex="+reader.getSex()+",age="+age+",time="+date+"]",Toast.LENGTH_SHORT).show();
search();
}
} catch (ParseException e) {
e.printStackTrace();
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
num = bookResult.size()-cunrrentI;
num1 = "符合要求的书还有"+String.valueOf(num)+"本";
resultTextView.setText(num1);
cunrrentI++;
if(cunrrentI<bookResult.size()){
bookImageView.setImageResource(bookResult.get(cunrrentI).getPic());
bookNameTextView.setText(bookResult.get(cunrrentI).getBookName());
bookTypeTextView.setText(bookResult.get(cunrrentI).getBookType());
bookAgeTextView.setText(bookResult.get(cunrrentI).getBookAge());
}else{
Toast.makeText(MainActivity.this,"没有啦!",Toast.LENGTH_SHORT).show();
}
}
});
}
//查找书
private void search() {
//如果为空,先初始化
if (bookResult == null) {
bookResult = new ArrayList<>();
}
//结果列表每次清空
//先清除之前的结果
bookResult.clear();
cunrrentI = 0;
//遍历书籍
for (int i = 0; i < books.size(); i++) {
Book book = books.get(i);
//如果符合条件,则加入结果列表
if (book != null) {
if (book.getBookAge() < age && (book.isHistory() == isHistory && book.isMystery() == isMystery && book.isLiterature() == isLiterature)) {
bookResult.add(book);
}
}
}
if (cunrrentI < bookResult.size()) {
bookImageView.setImageResource(bookResult.get(cunrrentI).getPic());
}
}
}
package model;
public class Reader {
private String name;
private String sex;
private Book book;
public String getName() {
return name;
}
public void setReader(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
}
package model;
import android.widget.TextView;
public class Book {
private int pic;
private String bookName;
private String bookType;
private int bookAge;
private boolean history;
private boolean mystery;
private boolean literature;
public Book(int pic, String bookName, String bookType, int bookAge, boolean history, boolean mystery, boolean literature) {
this.pic = pic;
this.bookName = bookName;
this.bookType = bookType;
this.bookAge = bookAge;
this.history = history;
this.mystery = mystery;
this.literature = literature;
}
public int getPic() {
return pic;
}
public void setPic(int pic) {
this.pic = pic;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getBookType() {
return bookType;
}
public void setBookType(String bookType) {
this.bookType = bookType;
}
public int getBookAge() {
return bookAge;
}
public void setBookAge(int bookAge) {
this.bookAge = bookAge;
}
public boolean isHistory() {
return history;
}
public void setHistory(boolean history) {
this.history = history;
}
public boolean isMystery() {
return mystery;
}
public void setMystery(boolean mystery) {
this.mystery = mystery;
}
public boolean isLiterature() {
return literature;
}
public void setLiterature(boolean literature) {
this.literature = literature;
}
}
1回答
同学你好,报的错不是代码问题,你先排查环境的问题。先重新创建一个project,代码什么的都不要改动看能不能运行起来。如果能运行起来,则表明你的AS升级了,导致原来项目的配置与现环境不匹配导致的。如果还想用原来的项目,你可以对比build.gradle文件,修改一下原来的内容,或者,你把原项目main下的三个文件夹直接复制到新项目中,覆盖新项目内容,就可以使用了。
相似问题