#GUI Randomizer ("actual and formal argument lists differ in length" error)

1 messages · Page 1 of 1 (latest)

agile forumBOT
#

This post has been reserved for your question.

Hey @plain grove! Please use /close or the Close Post button 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.

dim pecan
#

so what's the issue

#

oh i see

junior field
#

this class doesn't need a main, you can just instantiate it from the other one using the new keyword

dim pecan
#
  1. make the getRandomElement method static, it doesn't need to access anything from an instance of ADRandom anyway
  2. 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

junior field
#

you've:

  1. combined my advice and 0x150's
  2. taken 0x150's advice too literally
dim pecan
#

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

junior field
#

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

weary coral
#

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

weary coral
#

oh right

#

I fixed the code above

weary coral
#

also you can put this at the start of your main methode for the jframes to look less bad: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

weary coral
#

np neco

agile forumBOT
#

💤 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.