Help with for loop

Discussion in 'Plugin Development' started by David Knag, Jan 20, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    David Knag

    Here's the code:

    And it gives me this error:
    20:49:06 [SEVERE] Could not load 'plugins\comandRequest.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: net.
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
            at org.bukkit.craftbukkit.v1_4_R1.CraftServer.loadPlugins(CraftServer.ja
            at org.bukkit.craftbukkit.v1_4_R1.CraftServer.<init>(
            at net.minecraft.server.v1_4_R1.PlayerList.<init>(
            at net.minecraft.server.v1_4_R1.DedicatedPlayerList.<init>(SourceFile:11
            at net.minecraft.server.v1_4_R1.DedicatedServer.init(DedicatedServer.jav
    Caused by: java.lang.ClassNotFoundException: net.terrorsquad.commandRequest.Comm
            at$ Source)
            at$ Source)
            at Method)
            at Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            ... 9 more
    Anyone ever seen something like this?
    Thanks in advance
  2. Offline


    In your plugin.yml it is net.terrorsquad and you say that your class is org.terrorsquad.
  3. Offline

    ZeusAllMighty11 Retired Staff

    The stacktrace says "ClassNotFoundException' , meaning, well quite obviously, the class could not be found.

    ^_^ The above post.
  4. Offline

    David Knag

    Oh thanks, yeah I guess i forgot to change that when I changed the package name.

    So I changed the code a bit and I can't get it to iterate through this list

    Sorry for my noobery.
    This is what I get in the console:
    21:51:25 [INFO] davidknag issued server command: /fconfirm
    21:51:25 [INFO] [CommandRequest] running command
    21:51:25 [INFO] [CommandRequest] forloop
  5. Offline


    Use a "better" for loop:
    1. for(String command : commands){
    2. //This will automatically loop through your list of commands
    3. }
  6. Offline

    David Knag

    That's actually what I tried first. Same result.
    2. for(String command : commands){
    3. getLogger().info("forloop1");
    4. commandfix = command.replace("$p", sender.getName());
    5. commandfix = commandfix.replace("/", "");
    6. getLogger().info(commandfix);
    7. getLogger().info("forloop2");
    8. getServer().dispatchCommand(getServer().getConsoleSender(), commandfix);
    10. }

    and the logger doesn't output anything in the for loop.
  7. Offline


    It's also called for-each loop ;)

    David Knag
    Make a


    before the for loop. I think it will tell you why.
  8. Offline

    David Knag

    That's what the getLogger().info("forloop1");
    is for. That is the proper way to say something to the console in bukkit.
    Either way it didn't run the commands or say anything in the logger.
  9. Offline


    Ok follow these Steps:

    1. Learn Java
    2. A For loop will only be accessed if the condition is true!
    3. Before means to put the logger outside... not in the loop - when the condition is false you never will see this log!
    4. Hear to people who wanna help you :)
  10. Offline

    David Knag

    My first loop should have done the trick. I've been working with java for quite some time, but some things seem to puzzle me, probably because I learned PHP first, and I'm quite proficient in it.

    Yeah, I read that post over the other day, I haven't had time to try it, though. Also, wouldn't you not be able to use the method
    because `commands` is not a string, it's a list? I'm trying to iterate through this list and use each 'item' as a string. Man, in PHP this would be so much easier.

    I'm learning as I go, sorry to anger you that I can't seem to figure this out very well. Making mistakes is what learning is about, and I would totally get pissed off if I saw something similar in a forum relating to languages that I know very well.
  11. Offline


    You might need to invoke .toString() on it before actually passing it as a parameter, yes.

    Also, PHP is just bound to less rules than Java, that is why alot of stuff works in PHP and not in Java. (Besides, you should try using C or C++, which is even more strict)
  12. Offline


    Ok, firstly you dont anger me. And i dont wanted to piss you off. I just would be happy if suggestions and solutions which come from people who may be more experienced as you will be read. When i learned java i had not the privilege to just ask in a forum and everybody is supporting me. To this time we needed to go to workshops, which costs thousends of dollars or buy the 3 books which were available. So the most people worked only with the API... and believe me that was like hell...because there was nothing in it. But we learned to program and never had the "problems" like the new generation of programming has. Today its fine, there are many tutorials and a good commented Javadoc.

    But anyway so PHP is a scripting language - JAVA is a programming language. Sure there are some function which are very easy to use in PHP but in Java you could do the same. If you learn Java well you will find out that PHP is nice but not comparable to Java in its cardinality.

    So what i want to say is: Its ok to make mistakes and sure you will learn from, but you should to get deeper in you code to understand it. Take help you get and be willing also to work for youself in tutorials to solidify your skills.

    So the best is on the one hand learning on maybe plugin dev, but on the other hand on tutorials or your own probelms in school on work in the world idk, which you can solve by programming it. ( E.g. how works the Fibonacci-Sequence, how to programm my own simple scripting language... or something like that - will force you to get a better sight about all, as only in the repetitive work with plugins. )

    So good luck with learning the Java programming lang. and you are everytime welcome to ask :)

    BTW: If "commands" is a List / Map idk... check its size. When the size is 0 it wont go into the for loop
  13. Offline

    David Knag

    OH right, now I remember. Yes.
    So I spent a bit working on it, and I've got it finished. Here's the code in case anyone would like to look at it.
    Thanks for the help.

    Yeah, i realized what I did. capitalization error when I got the list from the config :oops: It returned [ ] in the logger, and I realized. Derp
    I wish my high school had a programming course, but sadly they don't. I learned PHP and SQL when I was in 7th grade, and there's really nothing within php that I can't accomplish, so I know I don't suck at things, It just takes time to learn.
    camyono likes this.
  14. Offline


Thread Status:
Not open for further replies.

Share This Page