2017-08-17 14 views
0

私は、クラスをセットに埋め込み、そのセットをモチーフのエンティティに挿入しようとしましたが、そのスタックトレースを返しています。InstantiationException on morphia mongodb

初めて、このエラーが発生したのは、初めてmorphiaエンティティ内で抽象クラスを使用していることです。

プレイヤーが/ kitを実行して自分のキットを選択したときにperformメソッドをトリガーする必要があるため抽象クラスを使用しました。 performメソッドをトリガーしようとすると、そのエラーを返します。

Caused by: java.lang.InstantiationException 
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[?:1.8.0_131] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_131] 
    at org.mongodb.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:72) ~[?:?] 
    at org.mongodb.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:91) ~[?:?] 
    at org.mongodb.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:105) ~[?:?] 
    at org.mongodb.morphia.mapping.EmbeddedMapper.readMapOrCollectionOrEntity(EmbeddedMapper.java:209) ~[?:?] 
    at org.mongodb.morphia.mapping.EmbeddedMapper.readCollection(EmbeddedMapper.java:144) ~[?:?] 
    at org.mongodb.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:47) ~[?:?] 
    at org.mongodb.morphia.mapping.Mapper.readMappedField(Mapper.java:850) ~[?:?] 
    at org.mongodb.morphia.mapping.Mapper.fromDb(Mapper.java:282) ~[?:?] 
    at org.mongodb.morphia.mapping.Mapper.fromDBObject(Mapper.java:193) ~[?:?] 
    at org.mongodb.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:134) ~[?:?] 
    at org.mongodb.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:146) ~[?:?] 
    at org.mongodb.morphia.query.MorphiaIterator.next(MorphiaIterator.java:117) ~[?:?] 
    at org.mongodb.morphia.query.QueryImpl.get(QueryImpl.java:236) ~[?:?] 
    at org.mongodb.morphia.query.QueryImpl.get(QueryImpl.java:227) ~[?:?] 
    at org.mongodb.morphia.dao.BasicDAO.findOne(BasicDAO.java:178) ~[?:?] 
    at eu.unionmc.kitpvp.player.PlayerManager.get(PlayerManager.java:49) ~[?:?] 
    at eu.unionmc.kitpvp.commands.kitCommand.onCommand(kitCommand.java:31) ~[?:?] 
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-550ebac-7019900] 

プレーヤー - Morphiaエンティティ

@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); 
} 
} 

キットのクラス

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クラス

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); 
} 

} 

キットコマンドクラス

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; 
} 
} 

答えて

0

KPlayerをデフォルト引数なしのコンストラクタ認証パブリックアクセスを与え、それは私が試したし、同じエラーがスローされますが、今alreadyExists方法にしました。この例外

+0

を修正する必要がありますPlayerManagerから –

関連する問題