Android I';m接收到无法解决代码中的符号错误
问题在于这段代码中有“quote”一词Android I';m接收到无法解决代码中的符号错误,android,Android,问题在于这段代码中有“quote”一词 if(quoteCopy.size()>20){ quotesCopy=newArrayList(); } displayMessageTextView.setText(引号); 这是我的全部代码: public class MainActivity extends AppCompatActivity { private Button addButton; private TextView displayMessageTextView;
if(quoteCopy.size()>20){
quotesCopy=newArrayList();
}
displayMessageTextView.setText(引号);
这是我的全部代码:
public class MainActivity extends AppCompatActivity {
private Button addButton;
private TextView displayMessageTextView;
private ArrayList<String> quotesCopy = new ArrayList<String>();
private ArrayList<String> quotes = new ArrayList<String>();
private Random randomGenerator = new Random();
private int previousNumber = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
quotes.add("You smart! You loyal! You're a genious!");
quotes.add("I appreciate you");
quotes.add("This is a major key");
quotes.add("They will try to close the door on U, just open it");
quotes.add("The key to more success is CoCo butter");
quotes.add("Congratulations, you played yourself");
quotes.add("Another one, no. Another two");
quotes.add("I changed... a lot");
quotes.add("They don't want you to jet ski");
quotes.add("The key is to have every key");
quotes.add("Almond milk + Cinnamon Toast Crunch = Major key to success");
quotes.add("Do you see that bamboo? Ain't nothing like bamboo. Blessup");
quotes.add("Bless up. Egg whites, Turkey bacon, Hashbrown, Water");
quotes.add("They wanna come stress me out? Heh, bye");
quotes.add("Lion Order");
quotes.add("Watch your back, but when you get out of the shower dry your back, it's a cold world");
quotes.add("Some of ya'll crabs");
quotes.add("ANOTHA ONE");
quotes.add("We jus seen 2 dolphins");
quotes.add("They don't want you to win");
quotes.add("Be A Star. Be A Superstar");
quotes.add("I remember when I ain't have a jacuzzi");
quotes.add("The other day the grass was brown, now it's green cuz I ain't give up");
quotes.add("In life everyone has a choice. The key is...make a right choice");
quotes.add("We have to get money. We have no choice. It cost money to eat");
quotes.add("I love my bamboo trees. I love fruits. I love apples.");
quotes.add("I told y'all this before, when you have a swimming pool do not use chlorine, use salt water");
quotes.add("The key is: never fold");
quotes.add("major key, get a pedicure and manicure once a week");
quotes.add("They dont want you to be healthy");
quotes.add("To make it thru the jungle you're gonna have to sweat");
quotes.add("They never said winning was easy");
quotes.add("It's important to shape up your hedges. It's like getting a haircut");
quotes.add("LIOOOOON");
quotes.add("To succeed, you must believe. When you believe you will succeed. ");
quotes.add("The key to success is to have a hammock");
quotes.add("Some people can't handle winning. I can.");
quotes.add("They don't want you to have lunch");
quotes.add("It's not an easy road but give thanks to the road");
quotes.add("The key to success is to have a lot of pillows. A lot.");
displayMessageTextView = (TextView) findViewById(R.id.displayMessageTextView);
displayMessageTextView.setText("Press the button to generate a random quote");
addButton = (Button) findViewById(R.id.addObjecttive);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Boolean isDifferent = false;
while (!isDifferent) {
int randomQuoteIndex = getRandomNumber();
String quote = quotes.get(randomQuoteIndex);
if (!quotesCopy.contains(quote)) {
isDifferent = true;
quotesCopy.add(quote);
}
if (quotesCopy.size() > 20)
quotesCopy = new ArrayList<String>();
}
displayMessageTextView.setText(quote);
}
});
}
public int getRandomNumber() {
int randomNumber = randomGenerator.nextInt(40);
while (previousNumber == randomNumber) {
randomNumber = randomGenerator.nextInt(40);
}
previousNumber = randomNumber;
return randomNumber;
}
}
public类MainActivity扩展了AppCompatActivity{
私人按钮添加按钮;
私有文本视图显示消息文本视图;
private ArrayList quotesCopy=new ArrayList();
private ArrayList quotes=new ArrayList();
私有随机生成器=新随机();
private int previousNumber=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
加上(“你聪明!你忠诚!你是个和蔼可亲的人!”);
加上(“我感谢你”);
添加(“这是一个主键”);
添加(“他们会试图关闭U上的门,只需打开它”);
添加(“可可黄油是取得更大成功的关键”);
加上(“祝贺你,你玩了你自己”);
加上(“另一个,第二个”);
添加(“我改变了……很多”);
加上(“他们不想让你坐摩托艇”);
添加(“关键是拥有每一把钥匙”);
添加(“杏仁牛奶+肉桂吐司酥脆=成功的关键”);
添加(“你看到那根竹子了吗?一点也不像竹子。Blessup”);
加上(“祝福你,蛋白,火鸡培根,哈什布朗,水”);
加上(“他们想给我压力吗?嘿,再见”);
添加(“狮子顺序”);
加上(“小心你的背,但当你洗完澡擦干你的背,这是一个寒冷的世界”);
加上(“一些你的螃蟹”);
引号。添加(“ANOTHA ONE”);
加上(“我们看到了两只海豚”);
添加(“他们不想让你赢”);
加上(“成为明星,成为超级明星”);
加上(“我记得我没有按摩浴缸的时候”);
加上(“前几天草是棕色的,现在是绿色的,因为我不会放弃”);
添加(“生活中每个人都有选择。关键是……做出正确的选择”);
加上(“我们必须赚钱,我们别无选择,吃东西要花钱”);
加上(“我爱我的竹子。我爱水果。我爱苹果。”);
加上(“我以前告诉过你们,当你们有游泳池时,不要用氯气,用盐水”);
添加(“关键是:永不折叠”);
添加(“主键,每周修脚修指甲一次”);
加上(“他们不希望你健康”);
加上(“要穿过丛林,你得流汗”);
加上(“他们从来没有说过胜利是容易的”);
加上(“塑造你的对冲很重要,就像理发一样”);
引号。添加(“lioooon”);
添加(“要成功,你必须相信。当你相信你会成功。”);
添加(“成功的关键是拥有吊床”);
加上(“有些人不能应付胜利,我可以。”);
加上(“他们不想让你吃午饭”);
加上(“这不是一条容易的路,但要感谢这条路”);
添加(“成功的关键是拥有很多枕头,很多。”);
displayMessageTextView=(TextView)findViewById(R.id.displayMessageTextView);
displayMessageTextView.setText(“按下按钮生成随机报价”);
addButton=(按钮)findViewById(R.id.addObjective);
addButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
布尔值isDifferent=false;
而(!不同){
int randomQuoteIndex=getRandomNumber();
字符串quote=quotes.get(randomQuoteIndex);
如果(!quotesCopy.contains(quote)){
isDifferent=true;
报价副本添加(报价);
}
如果(quotesCopy.size()>20)
quotesCopy=newArrayList();
}
displayMessageTextView.setText(引号);
}
});
}
public int getRandomNumber(){
int randomNumber=randomGenerator.nextInt(40);
while(previousNumber==随机数){
randomNumber=randomGenerator.nextInt(40);
}
previousNumber=随机数;
返回随机数;
}
}
您需要在while循环外部声明quote
以引用它
@Override
public void onClick(View v) {
Boolean isDifferent = false;
String quote ;
while (!isDifferent) {
int randomQuoteIndex = getRandomNumber();
quote = quotes.get(randomQuoteIndex);
if (!quotesCopy.contains(quote)) {
isDifferent = true;
quotesCopy.add(quote);
}
if (quotesCopy.size() > 20)
quotesCopy = new ArrayList<String>();
}
displayMessageTextView.setText(quote);
}
@覆盖
公共void onClick(视图v){
布尔值isDifferent=false;
字符串引用;
而(!不同){
int randomQuoteIndex=getRandomNumber();
quote=quotes.get(随机引用索引);
如果(!quotesCopy.contains(quote)){
isDifferent=true;
报价副本添加(报价);
}
如果(quotesCopy.size()>20)
quotesCopy=newArrayList();
}
displayMessageTextView.setText(引号);
}
您需要在while循环外部声明quote
以引用它
@Override
public void onClick(View v) {
Boolean isDifferent = false;
String quote ;
while (!isDifferent) {
int randomQuoteIndex = getRandomNumber();
quote = quotes.get(randomQuoteIndex);
if (!quotesCopy.contains(quote)) {
isDifferent = true;
quotesCopy.add(quote);
}
if (quotesCopy.size() > 20)
quotesCopy = new ArrayList<String>();
}
displayMessageTextView.setText(quote);
}
@覆盖
公共void onClick(视图v){
布尔值isDifferent=false;
字符串引用;
而(!不同){
int randomQuoteIndex=getRandomNumber();
quote=quotes.get(随机引用索引);
如果(!quotesCopy.contains(quote)){
isDifferent=true;
报价副本添加(报价);
}
如果(quotesCopy.size()>20)
quotesCopy=newArrayList();
}
displayMessageTextView.setText(引号);
}