java - InstantiationException on morphia mongodb -
im trying embed class set , insert set on morphia entity returning stacktrace.
its first time im using abstract class inside morphia entity first time seeing error.
i used abstract class because need trigger perform method when player choose kit doing /kit , kits owned player stored in set , inserted mongodb player document , saves when tried trigger perform method returns error.
caused by: java.lang.instantiationexception @ sun.reflect.instantiationexceptionconstructoraccessorimpl.newinstance(instantiationexceptionconstructoraccessorimpl.java:48) ~[?:1.8.0_131] @ java.lang.reflect.constructor.newinstance(constructor.java:423) ~[?:1.8.0_131] @ org.mongodb.morphia.mapping.defaultcreator.createinstance(defaultcreator.java:72) ~[?:?] @ org.mongodb.morphia.mapping.defaultcreator.createinstance(defaultcreator.java:91) ~[?:?] @ org.mongodb.morphia.mapping.defaultcreator.createinstance(defaultcreator.java:105) ~[?:?] @ org.mongodb.morphia.mapping.embeddedmapper.readmaporcollectionorentity(embeddedmapper.java:209) ~[?:?] @ org.mongodb.morphia.mapping.embeddedmapper.readcollection(embeddedmapper.java:144) ~[?:?] @ org.mongodb.morphia.mapping.embeddedmapper.fromdbobject(embeddedmapper.java:47) ~[?:?] @ org.mongodb.morphia.mapping.mapper.readmappedfield(mapper.java:850) ~[?:?] @ org.mongodb.morphia.mapping.mapper.fromdb(mapper.java:282) ~[?:?] @ org.mongodb.morphia.mapping.mapper.fromdbobject(mapper.java:193) ~[?:?] @ org.mongodb.morphia.query.morphiaiterator.convertitem(morphiaiterator.java:134) ~[?:?] @ org.mongodb.morphia.query.morphiaiterator.processitem(morphiaiterator.java:146) ~[?:?] @ org.mongodb.morphia.query.morphiaiterator.next(morphiaiterator.java:117) ~[?:?] @ org.mongodb.morphia.query.queryimpl.get(queryimpl.java:236) ~[?:?] @ org.mongodb.morphia.query.queryimpl.get(queryimpl.java:227) ~[?:?] @ org.mongodb.morphia.dao.basicdao.findone(basicdao.java:178) ~[?:?] @ eu.unionmc.kitpvp.player.playermanager.get(playermanager.java:49) ~[?:?] @ eu.unionmc.kitpvp.commands.kitcommand.oncommand(kitcommand.java:31) ~[?:?] @ org.bukkit.command.plugincommand.execute(plugincommand.java:44) ~[spigot.jar:git-spigot-550ebac-7019900]
player - morphia entity
@entity(value = "users", noclassnamestored = true) public class kplayer extends user{ private int kills, deaths, level; private long gold; private playerrank currentrank; private set<kit> ownedkits = new hashset<>(); @transient private float kdr; public int getkills() { return kills; } public void setkills(int kills) { this.kills = kills; } public int getdeaths() { return deaths; } public void setdeaths(int deaths) { this.deaths = deaths; } public float getkdr() { return kdr; } public void setkdr(float kdr) { this.kdr = kdr; } public playerrank getcurrentrank() { return currentrank; } public void setcurrentrank(playerrank currentrank) { this.currentrank = currentrank; } public int getlevel() { return level; } public void setlevel(int level) { this.level = level; } public long getgold() { return gold; } public void setgold(long gold) { this.gold = gold; } public set<kit> getownedkits() { return ownedkits; } public void setownedkits(set<kit> ownedkits) { this.ownedkits = ownedkits; } public void addkit(kit kit){ this.ownedkits.add(kit); } public boolean ownkit(kit kit){ return this.ownedkits.contains(kit); } }
kit class
package eu.unionmc.kitpvp.kit; import org.bukkit.material; public abstract class kit{ private string name; private string[] description; private boolean locked; private int leveltoapply; private long cost; private material icon; public kit() { } public kit(string name, boolean locked, int leveltoapply, long cost, material icon, string... description) { this.name = name; this.description = description; this.locked = locked; this.leveltoapply = leveltoapply; this.cost = cost; this.icon = icon; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string[] getdescription() { return description; } public void setdescription(string[] description) { this.description = description; } public boolean islocked() { return locked; } public void setlocked(boolean locked) { this.locked = locked; } public int getleveltoapply() { return leveltoapply; } public void setleveltoapply(int leveltoapply) { this.leveltoapply = leveltoapply; } public material geticon() { return icon; } public void seticon(material icon) { this.icon = icon; } public long getcost() { return cost; } public void setcost(long cost) { this.cost = cost; } public abstract void apply(); }
playermanager class
public class playermanager implements crud<kplayer,player> { private kitpool pool; public playermanager(kitpool pool) { this.pool = pool; } public kplayer create(player p){ kplayer kp = alreadyexists(p.getuniqueid().tostring()); if(kp == null){ kp = new kplayer(); kp.setuuid(p.getuniqueid().tostring()); kp.setusername(p.getname()); kp.setentity(p); kp.setlevel(0); kp.setcurrentrank(playerrank.none); kp.setkdr(0); kp.setkills(0); kp.setdeaths(0); kp.setgold(0); kp.addkit(new pvp()); update(kp); } return kp; } @override public kplayer get(player entry) { return pool.getplayerref().findone("uuid", entry.getuniqueid().tostring()); } @override public void update(kplayer entry) { pool.getplayerref().save(entry); } @override public void delete(kplayer entry) { pool.getplayerref().delete(entry); } @override public kplayer alreadyexists(string entry) { return pool.getplayerref().findone("uuid", entry); } }
kit command class
public class kitcommand implements commandexecutor { kitpvp plugin; public kitcommand(kitpvp plugin) { this.plugin = plugin; } @override public boolean oncommand(commandsender sender, command command, string s, string[] args) { if(!(sender instanceof player)) return true; player p = (player) sender; kplayer kp = plugin.getplayermanager().get(p); list<string> kitnames = plugin.getkitmanager().getkits().stream().map(kit::getname).collect(collectors.tolist()); string names = stringutils.join(kitnames, ", "); if(args.length == 0){ p.sendmessage("§cusage: /kit <kitname>"); p.sendmessage("§ekits: §6"+names); return true; } if(kp == null) return true; if(plugin.getkitmanager().getkitbyname(args[0]) == null){ p.sendmessage("§cthis kit doens't exists."); return true; } plugin.getkitmanager().perform(p, kp, plugin.getkitmanager().getkitbyname(args[0])); return false; } }
give kplayer default no args constructor auth public access , should fix exception
Comments
Post a Comment