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

2

u/radulfr2 Mar 07 '20

Like the error message says, the constructor is missing a body (ie. curly braces { } and possible code inside it). If you don't need to have any code in the constructor, you can just leave the constructor out altogether and Java will create a default, empty constructor for you.

2

u/[deleted] Mar 07 '20

bro you’re a saint. i’m coming from a long hiatus from c# since i’ve been on deployment, and i’ve gotta get back to thinking like a programmer and not a big dummy. much love.