So I was using Android Studio to create a simple "Famous Quotes" App and used most of the information on a tutorial video that showed how to complete a mini project like this. Unfortunately for me though I ended up getting this persistent error that I was not sure of solving. I tried to do things such as enabling auto imports for libraries, syncing with gradle, invalidating cache and restarting and cleaning the build with no success as a result.
What can I do to resolve this issue? I tried to find a library for this "bound" online but did not get a proper solution for it.
This is the code:
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;
Output:
Note: The output may show a different error but that is because I added a colon to "bound". Thought that could fix it as shown in the video as I did not spot that but it just made things worse.
Video used: https://www.youtube.com/watch?v=PQc_fSgZwyI
Nevermind it seems that the "bound" was actually not supposed to be there; removed it for testing and the program actually worked successfully.