r/javahelp • • Mar 07 '20

New to java, and need some help.

Hey boys, im pretty new to java and im just trying to fix this no-arg constructor compile error.

-----------------------------------------------------------

src\com\rs2hd\model\NPCDrop.java:13: error: missing method body, or declare abstract

public NPCDrop()

----------------------------------------------------------

Here is the code.

----------------------------------------------------------

package com.rs2hd.model;

import com.rs2hd.util.XStreamUtil;

import com.rs2hd.util.log.Logger;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

public class NPCDrop {

public NPCDrop();

public static Map<Integer, NPCDrop> npcDrops = new HashMap<Integer, NPCDrop>();

@>SuppressWarnings("unchecked")

public static void load() throws FileNotFoundException {

List<NPCDrop> list = (List<NPCDrop>) XStreamUtil.getXStream().fromXML(new FileInputStream("data/npcDrops.xml"));

for (NPCDrop drop : list) {

npcDrops.put(drop.getNpc(), drop);

}

Logger.getInstance().info("Loaded " + npcDrops.size() + " npc drops.");

}

public static NPCDrop forId(int id) {

return npcDrops.get(id);

}

public class Drop {

private int chance;

private Item[] items;

public int getChance() {

return chance;

}

public Item[] getItems() {

return items;

}

}

private int npc;

private Drop[] drops;

public int getNpc() {

return npc;

}

public Drop[] getDrops() {

return drops;

}

}

--------------------------------------------------------------------

If you can provide an insight that would be fantastic, thank you.

1 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Mar 07 '20

yes it is, when i ran my compiler it gave me an xstream error and said i needed a No Arg constructor, and this is my first time using it so im 100% sure im doing this like a brainlet.

2

u/[deleted] Mar 07 '20

and are you saying the

" public NPCDrop(); " is invalid syntax?

2

u/doodooz7 Mar 07 '20

Yes that’s invalid, turn it into a constructor with no arguments.

https://www.w3schools.com/java/java_constructors.asp

1

u/[deleted] Mar 07 '20

com.thoughtworks.xstream.converters.ConversionException: Cannot construct com.rs2hd.model.NPCDrop$Drop as it does not have a no-args constructor : Cannot construct com.rs2hd.model.NPCDrop$Drop as it does not have a no-args constructor

This is the error my program is giving me now, even though ive already added the no args constuctor, im starting to think its an issue with my jdk/jre versions.

1

u/reaper-is-happy Mar 07 '20

Try and reinstall it then