首页 > 解决方案 > 在 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;

输出: 在此处输入图像描述 注意:输出可能会显示不同的错误,但那是因为我在“绑定”中添加了一个冒号。认为可以修复它,如视频中所示,因为我没有发现它,但这只会让事情变得更糟。

使用的视频:https ://www.youtube.com/watch?v=PQc_fSgZwyI

标签: javaandroidandroid-studio-3.0android-studio-2.2

解决方案


Nevermind it seems that the "bound" was actually not supposed to be there; removed it for testing and the program actually worked successfully.


推荐阅读