Solved String Collection to Pages doesnt work with Spigot?

Discussion in 'Spigot Plugin Development' started by BluBOo, May 1, 2017.

  1. I wrote myself a method that converts a String Collection into an Array wich is splitted into "pages"
    when i run it without spigot it works..
    but whenever i run it with Spigot the method spits out "Error : null" instantly without going into its code
    ErrorLog:
    Code (171734errornullorgbukkitcommandcommandexceptionunhandledexceptionexecutingcommandblugotinpluginblugotapiv13atorgbukkitcommandplugincommandexecuteplugincommandjava46spigotjargit-spigot-3fb9445-fbb47e8atorgbukkitcommandsimplecommandmapdispatchsimplecommandmapjava141spigotjargit-spigot-3fb9445-fbb47e8atorgbukkitcraftbukkitv1_11_r1craftserverdispatchcommandcraftserverjava650spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1playerconnectionhandlecommandplayerconnectionjava1354spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1playerconnectionaplayerconnectionjava1189spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1packetplayinchatapacketplayinchatjava45spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1packetplayinchatapacketplayinchatjava1spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1playerconnectionutilsrunsourcefile13spigotjargit-spigot-3fb9445-fbb47e8atjavautilconcurrentexecutorsrunnableadaptercallunknownsource180_102atjavautilconcurrentfuturetaskrununknownsource180_102atnetminecraftserverv1_11_r1systemutilsasourcefile46spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1minecraftserverdminecraftserverjava747spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1dedicatedserverddedicatedserverjava399spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1minecraftservercminecraftserverjava678spigotjargit-spigot-3fb9445-fbb47e8atnetminecraftserverv1_11_r1minecraftserverrunminecraftserverjava576spigotjargit-spigot-3fb9445-fbb47e8atjavalangthreadrununknownsource180_102causedbyjavalangnosuchmethoderrorlibaryutilsstringstopagesljavautilarraylistiiljavalangstringatcommandhandlerslibarycommandhandlerfuntionslibarycommandhandlerjava65atcommandhandlerslibarycommandhandlerhandlelibarycommandhandlerjava24atcommandhandlerscommanddispatcherdispatchcommanddispatcherjava24atlibarylibarymainoncommandlibarymainjava56atorgbukkitcommandplugincommandexecuteplugincommandjava44spigotjargit-spigot-3fb9445-fbb47e815more (Unknown Language)):
     
    here my code
    Code (Text):
    public static String[] StringsToPages(Collection<? extends String> strs, int pageSize, int page) {

            String[] strings = strs.toArray(new String[strs.size() - 1]);

            int rest;
            int pages = (strings.length - (rest = strings.length % pageSize)) / pageSize;
            String[] re = new String[pageSize];
            // if given page count is less than 0 or higher than page count it will
            // return the last page
            if (page < 0 || page > pages + 1)
                page = pages + 1;
       
            if (page == pages + 1) {
                for (int i = 0; i < rest; i++) {
                    re[i] = strings[(strings.length - 1) - (rest - i - 1)];
                }

            } else {
            int e = 0;
                for (int i = (pageSize * page) - pageSize; i <= pageSize * page - 1; i++) {

                    re[e] = strings[i];
                    e++;
                }
            }

            return re;
        }

    here is the code to test it
    Code (Text):
    public static void main(String[] args)  {

            ArrayList<String> list = new ArrayList<>();

            list.add("Line 1: " + false);
            list.add("Line 2: " + true);
            //there is no line limit.
                            //Collection, Pagesize, return page
            String[] arr = StringsToPages(list, 5, 1);
            for (String s : arr) {
                if (s != null)
                    System.out.println(s);
                else
                    System.out.println("empty line");
            }
        }
     
    #1 BluBOo, May 1, 2017
    Last edited: May 1, 2017
  2. Update: i added a try catch block but i get an exception anyways.. wtf is this ?
     
  3. Look at the caused by:
    This isn't a problem with the method implementation itself. Maybe you didn't export your plugin fully/correctly?
     
    • Winner Winner x 1
  4. Lol using it in the same class works.. nice :D