TheHolyWaffle / TeamSpeak-3-Java-API

A Java wrapper of TeamSpeak's 3 server query API.
MIT License
307 stars 107 forks source link

Compiling Error [I did all what the tutorial say] #398

Closed DG5S closed 3 years ago

DG5S commented 3 years ago

Hey, I started programming my Bot and on the first start I get this Error. What did I wrong.

Error:

Exception in thread "main" java.lang.IllegalStateException: TS3Config cannot be modified after being used to create a TS3Query. Please make any changes to TS3Config *before* calling TS3Query's constructor.
    at com.github.theholywaffle.teamspeak3@1.3.0-with-dependencies/com.github.theholywaffle.teamspeak3.TS3Config.checkFrozen(TS3Config.java:350)
    at com.github.theholywaffle.teamspeak3@1.3.0-with-dependencies/com.github.theholywaffle.teamspeak3.TS3Config.setHost(TS3Config.java:69)
    at de.dg5s.dogame5.ts3bot.main.Main.main(Main.java:16)

My written Code:

import com.github.theholywaffle.teamspeak3.TS3Api;
import com.github.theholywaffle.teamspeak3.TS3Config;
import com.github.theholywaffle.teamspeak3.TS3Query;
import com.github.theholywaffle.teamspeak3.TS3Query.FloodRate;

public class Main {

    public static final TS3Config config = new TS3Config();
    public static final TS3Query query = new TS3Query(config);
    public static final TS3Api api = query.getApi();

    public static void main(String[] args) {

        config.setHost("127.0.0.1");
        config.setFloodRate(FloodRate.UNLIMITED);

        query.connect();

        api.login("serveradmin", "serverpassword");
        api.selectVirtualServerByPort(9987);
        api.setNickname("TS3-Manager"); 
    }
}

What can I do to fix that Problem. I have written the right serverpassword and the right host ip. I changed it here because of secret Informations.

This is the Tutorial I use.

Tumbledore commented 3 years ago

It is as the Error states "TS3Config cannot be modified after being used to create a TS3Query. Please make any changes to TS3Config before calling TS3Query's constructor"

You can't change the Configuration

config.setHost("127.0.0.1");
config.setFloodRate(FloodRate.UNLIMITED);

AFTER you construct the Query object

do something like this (I don't have an IDE at hand) and it should work:

public class Main {

    public static final TS3Config config = new TS3Config();

    public static void main(String[] args) {

        config.setHost("127.0.0.1");
        config.setFloodRate(FloodRate.UNLIMITED);
        TS3Query query = new TS3Query(config);

        query.connect();
        TS3Api api = query.getApi();

        api.login("serveradmin", "serverpassword");
        api.selectVirtualServerByPort(9987);
        api.setNickname("TS3-Manager"); 
    }
}
DG5S commented 3 years ago

Okay I will try it

DG5S commented 3 years ago

It works, thank uuuu so. I try my best to create a good Bot for us all.

Tumbledore commented 3 years ago

Just a Tip: Maybe get comfortable with the Basics of Java Programming before you start such a Project. There is quite the good Literature out there

DG5S commented 3 years ago

I programmed Java 3 years ago and I try new stuff