getDatabase() is returning NullPointerException please help

Discussion in 'Plugin Development' started by alta189, May 8, 2011.

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

    alta189

    Error
    MineMail.jar :

    Code:
    package com.alta189.minemail;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Logger;
    
    import javax.persistence.PersistenceException;
    
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MineMail extends JavaPlugin {
    
        public Logger log = Logger.getLogger("Minecraft");
        public String logPrefix = "[MineMail] ";
        public String mainDir = "plugins/mainDir";
    
        @Override
        public void onDisable() {
            ebeansFile.delete();
        }
    
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            PluginManager pm = getServer().getPluginManager();
    
            createMainDir();
    
            setupDatabase();
        }
    
        private void setupDatabase() {
            try {
                getDatabase().find(MailServer.class).findRowCount();
            } catch (PersistenceException ex) {
    
                installDDL();
            }
        }
    
         @Override
            public List<Class<?>> getDatabaseClasses() {
                List<Class<?>> list = new ArrayList<Class<?>>();
                list.add(MailServer.class);
                return list;
            }
    
        private void createMainDir() {
            File folderMain = new File(mainDir);
    
            if (!folderMain.exists()) {
                folderMain.mkdir();
            }
        }
    }
    
    MailServer.jar
    Code:
    package com.alta189.minemail;
    
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    import com.avaje.ebean.validation.NotNull;
    
    
    @Entity()
    @Table(name = "MailServer")
    public class MailServer {
    	@Id
    	private int id;
    	@NotNull
    	private String toWhom;
    	@NotNull
    	private String fromWhome;
    	@NotNull
    	private String message;
    	@NotNull
    	private Boolean read;
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	public int getId() {
    		return id;
    	}
    
    	public void setToWhom(String toWhom) {
    		this.toWhom = toWhom;
    	}
    
    	public String getToWhom() {
    		return toWhom;
    	}
    
    	public void setFromWhome(String fromWhome) {
    		this.fromWhome = fromWhome;
    	}
    
    	public String getFromWhome() {
    		return fromWhome;
    	}
    
    	public void setMessage(String message) {
    		this.message = message;
    	}
    
    	public String getMessage() {
    		return message;
    	}
    
    	public void setRead(Boolean read) {
    		this.read = read;
    	}
    
    	public Boolean getRead() {
    		return read;
    	}
    }
    
    FIXED: I forgot to add database: true in plugin.yml
    Oh the stupid mistakes that one can make when programming!! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  2. Offline

    rob4001

    i'm getting the same problem but i have the database: true in the plugin.yml :S
     
Thread Status:
Not open for further replies.

Share This Page