#GUI Randomizer ("actual and formal argument lists differ in length" error)
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @plain grove! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
this class doesn't need a main, you can just instantiate it from the other one using the new keyword
- make the getRandomElement method static, it doesn't need to access anything from an instance of ADRandom anyway
- call it from Main with
ADRandom.getRandomElement(listHere)
i'd also recommend putting the Random in a static final field in ADRandom, so you don't make a new one each time the method is called
you've:
- combined my advice and 0x150's
- taken 0x150's advice too literally
well you need to actually put the list you have in the place of listHere
yeah, you need to load the episodes from the file first
and then use that list you created and give it to getRandomElement
like you did here
then you need to load the 2 episode lists and give one of them into getRandomElement, depending on which button was clicked
you already know how to load a file into a list
well you already made code that works
either way you want, but loading it in main would make more sense
you need to let go of the idea that you can run java files, a java file just contains a class, which you can call methods on
thinking about it like running a java file is giving you the wrong idea of what’s happening
you already have a method in ADRandom that picks a random element from a list, you just need to give it a list to pick the element from
how you get that list is up to you
show latest of both classes
just paste content of both classes here
i'm just trying to see what both classes currently look like
and what's the current issue
i see getRandomElement isn't being used
why dont you do something like this
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import javax.swing.*;
public class EpisodePicker {
// drive function
public static void pickAndShowEpisode(String filename)
{
// reading text file into list in Java 7, from Java67.com
List<String> list = Collections.emptyList();
try {
list = Files.readAllLines(Paths.get(filename), StandardCharsets.UTF_8);
}
catch (IOException e){
//TODO Auto-generated catch block
e.printStackTrace();
}
// select random from list and print
JOptionPane.showMessageDialog(null, "Episode is" + EpisodePicker.getRandomElement(list));
}
// Function select an element base on index
// and return an element
public static String getRandomElement(List<String> list)
{
Random rand = new Random();
return list.get(rand.nextInt(list.size()));
}
}
and then call
EpisodePicker.pickAndShowEpisode("familyguy.txt")
in your buttons?
@plain grove ding
also you can put this at the start of your main methode for the jframes to look less bad: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
np 
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.