Solved java: cannot find symbol | symbol: method size()

Discussion in 'Spigot Plugin Development' started by Alw3ys, May 14, 2016.

  1. [​IMG]
    Can someone help me with that please Im ussing a 1.7.x 1.8.x version of Spigot but i need to use this ver. can someone help me please?
    #1 Alw3ys, May 14, 2016
    Last edited: May 15, 2016
  2. Rebuild it with a newer buildtools version.

    Gesendet von meinem Nexus 5 mit Tapatalk
  3. In place of size(), arrays have the .length to find how many entries they contain, same way you'd using it when you use args.length
  4. If thats whats u mean?
    Code (Java):

    return String.valueOf(String.valueOf(Bukkit.getServer().getOnlinePlayers().size()).length());
    because thats gave me the same error
  5. Length isn't a method. It's a field that you get.
  6. Well first off, why are you getting the value of a string from the value of a string of an object?

    Code (Text):
    That works fine, I don't really see the issue you are having.
  7. No that is not fine… It is .length not .size(). They have an older version so the getOnlinePlayers returns an array (Player[]) not a set (Set<Player>). Arrays use .length sets and those use .size()
  8. Basically what you did now is:
    return make it string(get the amount of chars of this string(number))

    Also, I would return it like this:
    Code (Java):
    if (Bukkit.class.getMethod("getOnlinePlayers").getReturnType() == Player[])
        return String.valueOf(((Player[])Bukkit.class.getMethod("getOnlinePlayers").invoke(Bukkit)).length);
        return String.valueOf(((Collection<? extends Player>)Bukkit.class.getMethod("getOnlinePlayers").invoke(Bukkit)).size());
  9. [​IMG]

    I am using the method that returns a Collection. To get the length, you must first use toArray(), as so:

  10. It was changed in 1.8, I think.
    He's using a <1.7 build.
    He doesn't have that method.
    Rather just let him use my method or make his own.
    • Informative Informative x 1
  11. I know.... But it used to return Player[] in like 1.7 (I think). So for newer .jar it returns Set<Player>, like yours. They are using the older Bukkit/spigot version so for them it returns Player[] in which they can use .lengh. If you don't believe me look at their eclipse picture
  12. That's so cool never knew you can do something like that! Get a method return type and stuff from .class
  13. Ah, I didn't realize that, my bad.
    • Agree Agree x 1
  14. Yep, just reflection. Most people prefer this rather than NMS, as you don't have to constantly update the package names. It just gets the fields/method names, and should work on almost every update (unless they change method/field names).
  15. And when they change that, like with a NBTTagByte you just do something like this:
    Code (Java):

    for (Method m : nmsTag.getMethods ())
        if (m.getName ().length () > 2)
        if (m.getReturnType () == int.class)
            d = m;
        else if (m.getReturnType () == byte.class)
            f = m;
        else if (m.getReturnType () == long.class)
            c = m;
        else if (m.getReturnType () == float.class)
            h = m;
        else if (m.getReturnType () == double.class)
            g = m;
        else if (m.getReturnType () == short.class)
            e = m;
    (Yes I actually made NBTTag classes to replace NMS xD)
    • Like Like x 1
  16. Guys I'm soo sorry but was a stupid a silly thing.
    Basically what happened is I forgot to import the spigot api :confused:
    So sorry thanks for the support :)
    • Funny Funny x 1
  17. Well, at least it was a simple fix! :p
  18. What does this error mean?

    The "Cannot find symbol" errors generally occur when you try to reference an undeclared variable in your code. A "Cannot find symbol" error means that the compiler cannot do this. Your code appears to be referring to something that the compiler doesn't understand.

    What things can cause this error?

    The general causes for a Cannot find symbol error are things like:

    • Incorrect spelling.

    • Wrong case. Halo is different from halo.

    • Improper use of acceptable identifier values (letters, numbers, underscore, dollar sign), my-class is not the same as myclass.

    • No variable declaration or variable is outside of the scope you are referencing it in.
    More about...cannot find symbol Error

    • Optimistic Optimistic x 1