NullPointerException - installDLL()

Discussion in 'Plugin Development' started by RightLegRed, Apr 3, 2011.

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

    Archelaus

    Has anyone used the new database system built into Bukkit yet? I'm attempting to. Using Dinnerbone's plugin as an example. Here's the error I'm getting:

    Code:
    11:36:14 [SEVERE] null loading HeroLock v0.0.1 (Is it up to date?)
    java.lang.NullPointerException
            at org.bukkit.plugin.java.JavaPlugin.installDDL(JavaPlugin.java:251)
            at com.herocraftonline.rightlegred.herolock.HeroLock.setupDatabase(HeroL
    ock.java:52)
            at com.herocraftonline.rightlegred.herolock.HeroLock.onEnable(HeroLock.j
    ava:33)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:127)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:514)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:216)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:115)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:93)
            at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:285)
            at org.bukkit.command.SimpleCommandMap$ReloadCommand.execute(SimpleComma
    ndMap.java:196)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:80
    )
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:2
    46)
            at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:391)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:377)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:283)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:375)

    and here is what the said error is talking about, in my code:

    Code:
        private void setupDatabase() {
            if(getDatabase() == null){
                installDDL();
            }
        }


    I tried using Dinnerbones way, but that also threw the same error.
     
  2. Offline

    rcjrrjcr

    This is where the exception is thrown from:
    Code:
    protected void installDDL() {
            SpiEbeanServer serv = (SpiEbeanServer)getDatabase();
            DdlGenerator gen = serv.getDdlGenerator();  //Line 251, JavaPlugin.class
            gen.runScript(false, gen.generateCreateDdl());
        }
    
    That means getDatabase() is returning null for you, in turn implying "ebean" in JavaPlugin is null. "ebean" is initiali[zs]ed in this part of the code:
    Show Spoiler
    Code:
    protected final void initialize(PluginLoader loader, Server server,
                PluginDescriptionFile description, File dataFolder, File file,
                ClassLoader classLoader) {
            if (!initialized) {
                this.initialized = true;
                this.loader = loader;
                this.server = server;
                this.file = file;
                this.description = description;
                this.dataFolder = dataFolder;
                this.classLoader = classLoader;
                this.config = new Configuration(new File(dataFolder, "config.yml"));
                this.config.load();
    
                if (description.isDatabaseEnabled()) { //Db server instance is initiali[zs]ed here
                    ServerConfig db = new ServerConfig();
    
                    db.setDefaultServer(false);
                    db.setRegister(false);
                   db.setClasses(getDatabaseClasses());
                    db.setName(description.getName());
                    server.configureDbConfig(db);
    
                    DataSourceConfig ds = db.getDataSourceConfig();
                    ds.setUrl(replaceDatabaseString(ds.getUrl()));
                    getDataFolder().mkdirs();
    
                    ClassLoader previous = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(classLoader);
                    ebean = EbeanServerFactory.create(db);
                    Thread.currentThread().setContextClassLoader(previous);
                }
            }
        }
    

    This means that isDatabaseEnabled() returns false.
    Checking PluginDescriptionFile.class shows that you need to add a "database:" entry in your plugin.yml for this to work.
    For example, this is mine:
    Show Spoiler
    Code:
    name: BuyAbilities
    version: 0.8
    main: com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.BuyAbilities
    description: Allows the purchase of temporary abilities with iConomy money.
    authors:
        - rcjrrjcr
    database: true
    commands:
        bab:
            description: Alias for buyab
            usage: /bab [categories|category|page|current|buy|rent|rentuse|info|help]
    
        buyab:
            description: Buy abilities via this command
            usage: /buyab [categories|category|page|current|buy|rent|rentuse|info|help]
    


    Works for me. However, I still get this error:

    Code:
    javax.persistence.PersistenceException: com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.PurchasedAbility is NOT an Entity Bean registered with this server?
           at com.avaje.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:1031)
           at com.avaje.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:988)
           at com.avaje.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:1024)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.storage.StorageEBeans.getPlayerData(StorageEBeans.java:31)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.BuyAbilities.processLogonLogoff(BuyAbilities.java:757)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.PlayerLoaderSaver.run(BuyAbilitiesPlayerListener.java:87)
           at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:33)
           at java.lang.Thread.run(Unknown Source)
    
    EDIT: I fail at bbCode :/

    EDIT2: So much for this, eh?
    Not like anyone knows how to use EBeans properly as of now.
     
  3. Offline

    Drakia

  4. Offline

    rcjrrjcr

    Ah. I stand corrected then. Forgot about the annotations.:D I still think that EBeans is too complicated.
     
  5. Offline

    Dinnerbone Bukkit Team Member

    You set database:true in your plugin description file, you override getDatabaseClasses() to return a list of models that you use, and then you go to town.
     
  6. Offline

    rcjrrjcr

    I did that, and I got a NFE.
    Code:
     java.lang.NumberFormatException: For input string: "Jump: jump to aim in world world."
           at java.lang.NumberFormatException.forInputString(Unknown Source)
           at java.lang.Integer.parseInt(Unknown Source)
           at java.lang.Integer.valueOf(Unknown Source)
           at com.avaje.ebeaninternal.server.core.BasicTypeConverter.toInteger(BasicTypeConverter.java:286)
           at com.avaje.ebeaninternal.server.type.ScalarTypeInteger.toBeanType(ScalarTypeInteger.java:68)
           at com.avaje.ebeaninternal.server.type.ScalarTypeInteger.toBeanType(ScalarTypeInteger.java:36)
           at com.avaje.ebeaninternal.server.deploy.id.IdBinderSimple.convertSetId(IdBinderSimple.java:223)
           at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.convertId(BeanDescriptor.java:1729)
           at com.avaje.ebeaninternal.server.persist.DefaultPersister.deleteMany(DefaultPersister.java:494)
           at com.avaje.ebeaninternal.server.core.DefaultServer.delete(DefaultServer.java:1808)
           at com.avaje.ebeaninternal.server.core.DefaultServer.delete(DefaultServer.java:1800)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.storage.StorageEBeans.writePlayerData(StorageEBeans.java:38)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.BuyAbilities.processLogonLogoff(BuyAbilities.java:775)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.PlayerLoaderSaver.run(BuyAbilitiesPlayerListener.java:87)
           at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:33)
           at java.lang.Thread.run(Unknown Source)
    
    Why is Ebean parsing toString()??
     
  7. Offline

    Dinnerbone Bukkit Team Member

    Show me your code.
     
  8. Offline

    Archelaus


    I had missed out getDatabaseClasses().

    Thanks @Drakia
     
  9. Offline

    rcjrrjcr

  10. Offline

    Dinnerbone Bukkit Team Member

    Since you said you've moved it to another class etc, please give me an updated exception matching the current code.
     
  11. Offline

    rcjrrjcr

    Sorry. I got 503'd and my edited post went down the drain without me noticing.
    Code:
     java.lang.NumberFormatException: For input string: "com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.storage.StoredAbility$$EntityBean$BuyAbilities@1"
           at java.lang.NumberFormatException.forInputString(Unknown Source)
           at java.lang.Integer.parseInt(Unknown Source)
           at java.lang.Integer.valueOf(Unknown Source)
           at com.avaje.ebeaninternal.server.core.BasicTypeConverter.toInteger(BasicTypeConverter.java:286)
           at com.avaje.ebeaninternal.server.type.ScalarTypeInteger.toBeanType(ScalarTypeInteger.java:68)
           at com.avaje.ebeaninternal.server.type.ScalarTypeInteger.toBeanType(ScalarTypeInteger.java:36)
           at com.avaje.ebeaninternal.server.deploy.id.IdBinderSimple.convertSetId(IdBinderSimple.java:223)
           at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.convertId(BeanDescriptor.java:1729)
           at com.avaje.ebeaninternal.server.persist.DefaultPersister.deleteMany(DefaultPersister.java:494)
           at com.avaje.ebeaninternal.server.core.DefaultServer.delete(DefaultServer.java:1808)
           at com.avaje.ebeaninternal.server.core.DefaultServer.delete(DefaultServer.java:1800)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.storage.StorageEBeans.writePlayerData(StorageEBeans.java:37)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.BuyAbilities.processLogonLogoff(BuyAbilities.java:775)
           at com.rcjrrjcr.bukkitplugins.buyabilitiesplugin.PlayerLoaderSaver.run(BuyAbilitiesPlayerListener.java:87)
           at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:33)
           at java.lang.Thread.run(Unknown Source)
    
    I've been poking around in the source of EBeans to find where it went wrong but it's too complex for me to understand.
     
Thread Status:
Not open for further replies.

Share This Page