java - 在 Android Studio 上查找方法 bound(int) 的符号时出错,不确定此问题来自何处
问题描述
因此,我使用 Android Studio 创建了一个简单的“名言”应用程序,并使用了教程视频中的大部分信息,该视频展示了如何完成这样的迷你项目。对我来说不幸的是,虽然我最终得到了这个我不确定解决的持续错误。我尝试做一些事情,例如为库启用自动导入、与 gradle 同步、使缓存无效以及重新启动和清理构建但没有成功。
我可以做些什么来解决这个问题?我试图在网上为这个“绑定”找到一个图书馆,但没有找到合适的解决方案。
这是代码:
package com.example.technologyquotes;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Random;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Button;
import android.view.View;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
Random random = new Random();
TextView textQuote;
Button showQuoteButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textQuote = findViewById(R.id.textQuote);
showQuoteButton = findViewById(R.id.showQuoteButton);
showQuoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
displayQuote();
}
});
displayQuote();
}
protected void displayQuote(){
int randNum = random.nextInt( bound: (6+1) - 1) + 1;
String randQuote = "";
switch(randNum){
case 1 :
randQuote = getString(R.string.quote1);
break;
case 2 :
randQuote = getString(R.string.quote2);
break;
case 3 :
randQuote = getString(R.string.quote3);
break;
case 4 :
randQuote = getString(R.string.quote4);
break;
case 5 :
randQuote = getString(R.string.quote5);
break;
case 6 :
randQuote = getString(R.string.quote6);
break;
}
textQuote.setText(randQuote);
}
}
//Part that keeps breaking the code:
random.nextInt( bound: (6+1) - 1) + 1;
输出: 注意:输出可能会显示不同的错误,但那是因为我在“绑定”中添加了一个冒号。认为可以修复它,如视频中所示,因为我没有发现它,但这只会让事情变得更糟。
解决方案
Nevermind it seems that the "bound" was actually not supposed to be there; removed it for testing and the program actually worked successfully.
推荐阅读
- c++ - 使用 MySQL 连接器 C++ 链接 mysqlcppconn-static 时出现问题
- javascript - 将图像添加到使用 jQuery
- java - Tomcat 权限被拒绝 /home/ubuntu 无法 GET、POST
- javascript - 是否可以以编程方式判断 webp 循环何时结束?
- listview - Flutter/Firestore - 在流构建器中的动态列表视图上实现“分页”
- excel - 如何创建超链接数组(Excel VBA)?
- reporting-services - Ssrs,使用通配符计算一个文件
- c - 为什么'x'的值打印在main中,而它可能在从abc()出来时被释放?
- php - 使用多个 where 子句选择多个查询
- android-studio - 无法生成 APK - 出现错误:无法解决:com.github.2359media:Easy AndroidAnimations:0.8