Results 1 to 5 of 5
  1. #1
    Shredderr is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Smile Toe eigening vanuit andere classe

    Ik probeer het spel woordmix te maken in java mbv het programma intelliJ. de bedoeling van het spel is om mbv 13dobbelstenen(met letters) woorden te vormen. de waarden in de arraylist zijn vaste waarde voor elke dobbelsteen in de methode doeworp proberen we per dobbelsteen 1 random letter eruit te halen en weer te geven.
    Ik zit vast bij het toe eigenen aan eindletter. de methode doeworp wordt opgevraagt vanuit een andere classe, na het uitvoeren van de main code zegt het programma dat er een probleem is met de regel " eindletters = eindletters + result.substring(getal, 1);". iemand enig idee ? Alvast bedankt :)

    public final class Worp {

    public Dobbelsteen[] dobbelstenen; //array maken
    String eindletters;

    public Worp() { //waarde geven aan dobbelstenen
    List<String> waarden = Arrays.asList("I U B H A Y", "K X E D G N", "T W I A R D", "M N J S G E", "N P S G L E", "I A C Q S H", "R F N @ E L", "B N Z S V E", "S R U H O E", "K O A D R N", "R A H F M I", "C D E S I M", "E I T U D L");
    this.dobbelstenen = new Dobbelsteen[waarden.size()];
    for (int i = 0; i < waarden.size(); i++)
    dobbelstenen[i] = new Dobbelsteen(waarden.get(i));
    }

    public void doeWorp() //zijde geven, waarde berekenen + waarden substringen/ splitsen
    {
    String result = "";
    Random r = new Random(5);
    int getal = r.nextInt();



    for (int i = 0; i< dobbelstenen.length; i++) {
    result = result + " " + dobbelstenen[i];

    eindletters = eindletters + result.substring(getal, 1);

    }
    }

    public void setEindletters(String eindletter) {
    this.eindletters = eindletter;
    }
    }
    Last edited by Shredderr; 01-24-2012 at 05:47 PM.

  2. #2
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: Toe eigening vanuit andere classe

    Can you give us the error that is displayed?

    I don't know what the "Dobbelstenen" class is, but this looks like it could be a problem.
    Java Code:
    result = result + " " + dobbelstenen[i];
    You're trying to add an instance of the dobbelstenen class to a string.

    Google Translate
    Kunt u ons de fout die wordt weergegeven?

    Ik weet niet wat de "Dobbelstenen" klasse is, maar dit ziet eruit als het kan een probleem zijn.
    Java Code:
    result = result + " " + dobbelstenen[i];
    Je probeert een instantie van de dobbelstenen klasse toe te voegen aan een string.

  3. #3
    Shredderr is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Toe eigening vanuit andere classe

    srry for the other language, i'll try in english,
    I actually dont need anything from the class Dobbelstenen :s
    for some reason he needs that class .., + the arraylist doesn' get any values.

    this is the error... it just says were the error is...
    Toe eigening vanuit andere classe-knipsel.png

  4. #4
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: Toe eigening vanuit andere classe

    Ok, english is much easier thanks .

    The error tells you where it happened but also gives you much more useful information. It tells you exactly what method caused the problem (substring()) and what error it threw (StringIndexOutOfBoundsException). It also gives you "String index out of range: -1157408321". So take a look at the variable your passing to that method (the random number) and make sure it is the value you want to be passing.

  5. #5
    Shredderr is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Toe eigening vanuit andere classe

    Ok thanks, I'll look into it :)

Similar Threads

  1. Unable to call classe constructor from main
    By serdimay in forum New To Java
    Replies: 13
    Last Post: 08-30-2011, 10:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •