Results 1 to 8 of 8
  1. #1
    pingu is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default no-args constructor? (Also a hello to everyone)

    Hi, I'm new to the forum.
    I have mainly joined this community so that I can seek help, yet also gain more knowledge on Java.

    I'm currently working on a game source so that I can learn a bit about it. Somehow I have managed to change something or not include something. (I have a feeling it was my cat on my keyboard whilst I was away lol) I'm not at all sure what it is, I was wondering if someone could possibly tell me what's wrong. I would appreciate it greatly, here is what I was receiving when compiling:


    [RS2Server] Loading Cache...
    java.lang.NullPointerException
    at org.dementhium.cache.Cache.<init>(Cache.java:61)
    at org.dementhium.cache.Cache.<clinit>(Cache.java:23)
    at org.dementhium.RS2Server.main(RS2Server.java:25)
    [RS2Server] Loading World...
    [PacketManager] Loading packet handlers...
    [PacketManager] Loaded 45 packet handlers.
    [PacketManager] Loading packet handlers...
    [PacketManager] Loaded 45 packet handlers.
    [ClanManager] Loading clans....
    com.thoughtworks.xstream.converters.ConversionExce ption: Cannot construct org.dementhium.content.clans.Clan as it does not have a no-args constructor : Cannot construct org.dementhium.content.clans.Clan as it does not have a no-args constructor
    ---- Debugging information ----
    message : Cannot construct org.dementhium.content.clans.Clan as it does not have a no-args constructor
    cause-exception : com.thoughtworks.xstream.converters.reflection.Obj ectAccessException
    cause-message : Cannot construct org.dementhium.content.clans.Clan as it does not have a no-args constructor
    class : java.util.HashMap
    required-type : org.dementhium.content.clans.Clan
    path : /map/entry/org.dementhium.content.clans.Clan
    line number : 4
    -------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vert(TreeUnmarshaller.java:88)
    at com.thoughtworks.xstream.core.AbstractReferenceUnm arshaller.convert(AbstractReferenceUnmarshaller.ja va:55)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vertAnother(TreeUnmarshaller.java:75)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vertAnother(TreeUnmarshaller.java:59)
    at com.thoughtworks.xstream.converters.collections.Ab stractCollectionConverter.readItem(AbstractCollect ionConverter.java:77)
    at com.thoughtworks.xstream.converters.collections.Ma pConverter.populateMap(MapConverter.java:79)
    at com.thoughtworks.xstream.converters.collections.Ma pConverter.unmarshal(MapConverter.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vert(TreeUnmarshaller.java:81)
    at com.thoughtworks.xstream.core.AbstractReferenceUnm arshaller.convert(AbstractReferenceUnmarshaller.ja va:55)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vertAnother(TreeUnmarshaller.java:75)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vertAnother(TreeUnmarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.sta rt(TreeUnmarshaller.java:142)
    at com.thoughtworks.xstream.core.AbstractTreeMarshall ingStrategy.unmarshal(AbstractTreeMarshallingStrat egy.java:33)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream .java:907)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream .java:893)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.j ava:845)
    at org.dementhium.io.XMLHandler.fromXML(XMLHandler.ja va:62)
    at org.dementhium.content.clans.ClanManager.<init>(Cl anManager.java:23)
    at org.dementhium.model.World.load(World.java:93)
    at org.dementhium.RS2Server.main(RS2Server.java:27)
    Caused by: com.thoughtworks.xstream.converters.reflection.Obj ectAccessException: Cannot construct org.dementhium.content.clans.Clan as it does not have a no-args constructor
    at com.thoughtworks.xstream.converters.reflection.Pur eJavaReflectionProvider.newInstance(PureJavaReflec tionProvider.java:71)
    at com.thoughtworks.xstream.converters.reflection.Abs tractReflectionConverter.instantiateNewInstance(Ab stractReflectionConverter.java:279)
    at com.thoughtworks.xstream.converters.reflection.Abs tractReflectionConverter.unmarshal(AbstractReflect ionConverter.java:149)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.con vert(TreeUnmarshaller.java:81)
    ... 19 more
    Press any key to continue . . .


    Thanks for your help

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: no-args constructor? (Also a hello to everyone)

    The error said that you have to define a no-args constructor for your class. It is a constructor that doesn't accept any argument or parameters.

  3. #3
    pingu is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: no-args constructor? (Also a hello to everyone)

    Thanks for defining which type :o)

  4. #4
    pingu is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: no-args constructor? (Also a hello to everyone)

    Could you please tell me where the no-args constructor would go. I would be very grateful thanks, as I have got myself so confused over this whole scrambled mess :'(
    also after this I am going to change to something less complicated and try to progress. :)

    Here is the text:

    Java Code:
    package org.dementhium.content.clans;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    
    import org.dementhium.model.player.Player;
    import org.dementhium.net.ActionSender;
    import org.dementhium.util.Misc;
    
    
    public class Clan {
    
    	private String roomName;
    	private String roomOwner;
    	private int joinReq = 0;
    	private int talkReq = 0;
    	private int kickReq = 7;
    	private HashMap<String, Byte> ranks;
    	private transient List<Player> members;
    	private transient boolean lootsharing;
    
    	public Clan(String owner, String name) {
    		this.roomName = name;
    		this.roomOwner = owner;
    		setTransient();
    	}
    
    	public void setTransient() {
    		setLootsharing(false);
    		if(kickReq == 0) {
    			kickReq = 7;
    		}
    		if (members == null) {
    			this.members = new ArrayList<Player>();
    		}
    		if (ranks == null) {
    			this.ranks = new HashMap<String, Byte>();
    		}
    	}
    
    	public String getName() {
    		return roomName;
    	}
    	public String getOwner() {
    		return roomOwner;
    	}
    	public void rankUser(String name, int rank) {
    		if (!ranks.containsKey(name)) {
    			ranks.put(name, (byte) rank);
    		} else {
    			ranks.remove(name);
    			ranks.put(name, (byte) rank);
    		}
    	}
    
    	public Byte getRank(Player player) {
    		if (Misc.formatPlayerNameForProtocol(player.getUsername()).equals(roomOwner)) {
    			return 7;
    		} else if (player.getRights() == 2) {
    			return 127;
    		} else if (ranks.containsKey(player.getUsername())) {
    			return ranks.get(player.getUsername());
    		}
    		return -1;
    	}
    
    	public boolean canJoin(Player player) {
    		byte rank = 0;
    		if(ranks.containsKey(player.getUsername())) {
    			rank = ranks.get(player.getUsername());
    		}
    		return rank >= joinReq;
    	}
    
    	public boolean canTalk(Player player) {
    		byte rank = 0;
    		if(ranks.containsKey(player.getUsername())) {
    			rank = ranks.get(player.getUsername());
    		}
    		return rank >= talkReq;
    	}
    
    	public void toggleLootshare() {
    		lootsharing = !lootsharing;
    		String message = "";
    		if(lootsharing) {
    			message = "Lootshare has been enabled.";
    		} else {
    			message = "Lootshare has been disabled.";
    		}
    		for(Player pl : members) {
    			ActionSender.sendMessage(pl, message);
    			ActionSender.sendConfig(pl, 1083, lootsharing ? 1 : 0);
    		}
    	}
    	public void addMember(Player member) {
    		members.add(member);
    	}
    
    	public void setName(String name) {
    		this.roomName = name;
    	}
    
    	public List<Player> getMembers() {
    		return members;
    	}
    
    	public void removeMember(Player player) {
    		members.remove(player);
    	}
    
    	public HashMap<String, Byte> getRanks() {
    		return ranks;
    	}
    
    	public void setLootsharing(boolean lootsharing) {
    		this.lootsharing = lootsharing;
    	}
    
    	public boolean isLootsharing() {
    		return lootsharing;
    	}
    
    	public void setTalkReq(int talkReq) {
    		this.talkReq = talkReq;
    	}
    
    	public int getTalkReq() {
    		return talkReq;
    	}
    
    	public void setJoinReq(int joinReq) {
    		this.joinReq = joinReq;
    	}
    
    	public int getJoinReq() {
    		return joinReq;
    	}
    
    	public int getKickReq() {
    		return kickReq;
    	}
    }
    Last edited by DarrylBurke; 06-19-2012 at 04:04 AM. Reason: Replace COLOR tags with CODE tags

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: no-args constructor? (Also a hello to everyone)

    This is how to declare a no-args constructor:

    Java Code:
    public class Clan {
        ...
        ...
    
        public Clan() {
            // Constructor code here.
        }
    
        ...
        ...
    }

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

    Default Re: no-args constructor? (Also a hello to everyone)

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    pingu is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: no-args constructor? (Also a hello to everyone)

    OK, thanks.

  8. #8
    pingu is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: no-args constructor? (Also a hello to everyone)

    Thanks, I appreciate it. :)

Similar Threads

  1. Replies: 5
    Last Post: 12-14-2011, 01:47 PM
  2. use of String[] args
    By mallikanala in forum New To Java
    Replies: 1
    Last Post: 06-21-2011, 08:09 AM
  3. Args[0]
    By hakan123 in forum New To Java
    Replies: 11
    Last Post: 12-03-2009, 05:40 PM
  4. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •