Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How To Fix "ClassNotFoundException"

Comments in 'Plugin Development' started by EdwardAllington, Dec 26, 2015.

  1. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Hello everyone. I am trying to make my first plugin an am having some issues. The plugin is called "Clans" and is basically a modified fork of FactionsPro, in witch I am modifying to where the "factions" are called "clans" and the main command is "/c" instead of "/f". (I want my first plugin to be simple of course.) However, when I tested the plugin, the server crashed and I got a crash dump. When I submitted the crash dump at http://pmt.mcpe.me/, it gave error code, containing "ClassNotFoundException". So I was wondering if some more experienced plugin developers could please help me with this.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    ClassNotFoundException -> (a) Class (has) Not (been) Found -> A class hasn't been found -> Somewhere in your code, you are using an unknown class. -> Send us your code.
  3. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    The code is here in this ZIP file. I put all of the code files in it.

    Attached Files:

  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I seem to have some problems downloading files from this site on mobile, so I can't check it. But remember:
    1. Your files must be placed in the src directory according to PSR-0 standards.
    2. Check your cases, in case your plugin is run on a case sensitive filesystem.
    3. Correct imports?
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I checked your plugin.yml, please tell me what is that:
    Code:
    #...
    main: src
    #...
    KubixQ and PEMapModder like this.
  6. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    I thought it was what was supposed to go there. But I found out it wasn't.
    This is my current plugin.yml.
    PHP:
    nameClans
    author
    Edwardthedog2
    description
    A plugin for giving your server a clans system.
    version1.0.0
    main
    Clans\Main
    api
    : [1.12.0]
    commands:
      
    c:
        
    description: use /c help for all commands
        permission
    c.command
    permissions
    :
      
    f.command:
        default: 
    true
        description
    "Allow use of all clan commands"
      
    f.override:
        default: 
    op
        description
    "Allows op users to override clans"
    Last edited: Dec 27, 2015
  7. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Create a new folder called "Clans" in src folder and move everything in the src folder into the "Clans" folder
    in your plugin.yml, change
    Code:
    main: Clans\Main
    to
    Code:
    main: Clans\ClanMain
  8. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Okay, I did that, but now the server crashes when I try to run it saying that the class isn't found.
  9. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Make sure you're declaring the right class in your PHP file... BTW, I suggest you learn PHP and the PocketMine API before you start making a plugin like this. ;) :p
    Vaivez66 likes this.
  10. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Whats the full error message?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make your file into a zip, submit it to http://pmt.mcpe.me with all three inspections at the bottom enabled and see the results.
    applqpak likes this.
  12. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Okay, done. The "Bad Practice" and "Syntax Errors" inspections passed, but the " Classpath" inspection returned an error that says "
    • Main class file expected at src/Clans/ClanMain.php but it is not a file"
  13. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Error: Class Clans\ClanMain not found
  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Check if /scr/Clans/ClanMain.php exists!
  15. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    I just checked. It does exist.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because it is src, not scr. It means source.
    Remember this lesson. You will keep facing conditions like this in the future, like reading "a"s as "u"s.
  17. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Okay got it. But I changed that, and it gives me the same error.
  18. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Like I said earlier, make sure you have it pointing to the right class.

    How it should go:

    PluginFoler(folder) -> plugin.yml & src -> Clans\Main.php
    And in the plugin.yml file make sure you have it set like:
    Code:
    main: Clans\Main
  19. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Awesome now the plugin doesn't crash the server. However even though it has /c in the help menu when I type "/c" (the plugins main command) it doesn't do anything. Plus this appears in the console when I first start the server.
    Code:
    [15:30:00] [Server thread/NOTICE]: InvalidArgumentException: "Argument 1 passed to Clans\ClanListener::__construct() must be an instance of Clans\ClanMain, instance of Clans\Main given, called in phar://C:/Users/edwar/Desktop/PocketMine-MP/plugins/ClansBuild19.phar/src/Clans/Main.php on line 49 and defined" (E_RECOVERABLE_ERROR) in "/ClansBuild19.phar/src/Clans/ClanListener" at line 27
    
  20. EdwardAllington
    Offline

    EdwardAllington Active Member

    Joined:
    Jan 29, 2015
    Posts:
    78
    Minecraft User:
    Edwardthedog2
    Okay, I think I found the problem in my "ClanListener.php" file.

Share This Page

Advertisement