I have this exception when trying to parse a JSON file with GSON:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: class com.sun.javafx.jmx.HighlightRegion declares multiple JSON fields named hash
I have tested a little to what causes this, and I found that it only occurs when I create a Object that has an Event object as a member. In this case, I am trying to create a List of Quest objects that eventually have Event objects.
package Quests;
import Events.EventSequence;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Quest {
public static void parseQuest() {
Gson gson = new Gson();
FileReader questGSON;
try {
questGSON = new FileReader(QUEST_FILE);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
JsonObject questJSON = gson.fromJson(questGSON, JsonObject.class);
questList = new ArrayList<>();
for(Map.Entry<String, JsonElement> element : questJSON.entrySet()) {
questList.add(gson.fromJson(element.getValue(), Quest.class));
}
}
}
I am using javafx in that class in the following way:
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
public abstract class Event implements EventHandler<ActionEvent> {
// members of this class
private String title, text;
private Button[] buttonSet;
protected Entity other;
protected Event nextEvent;
public abstract Event chooseNewEvent(String command);
#Override
public void handle(ActionEvent event) {
// Get the name of the button
String command = ((Button) event.getSource()).getText();
displayNewEvent(chooseNewEvent(command));
}
}
The only information I could find regarding this was:
https://github.com/wpilibsuite/shuffleboard/issues/358
Could someone point me in some direction to fix my bug?
I found out that it was a Button array from javafx.scene.control.Button in my Event class that was causing the problem. I fixed it by making it transient so it would get ignored by GSON and not cause any problems.
Nevertheless, I have no idea why the Button array would cause this exception. Any thoughts?
Related
I've tried to modify minecraft by adding a new item called "uranium". Therefore I created the class "Trauma.java" in the main package and a few other classes listed below.
All packages and classes:
Package Explorer
Trauma.java
package main;
import items.ItemUranium;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import proxy.ServerProxy;
#Mod(modid = Trauma.MODID)
public class Trauma {
public static final String MODID = "Trauma";
#SidedProxy(clientSide = "proxy.ClientProxy", serverSide = "proxy.ServerProxy")
public static ServerProxy proxy;
public static ItemUranium uranium = new ItemUranium();
#EventHandler
public void preInit(FMLPreInitializationEvent event) {
GameRegistry.register(uranium);
}
#EventHandler
public void init(FMLInitializationEvent event) {
proxy.registerClientStuff();
}
#EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
}
BasicItem.java
package items;
import net.minecraft.item.Item;
public class BasicItem extends Item {
public BasicItem(String name) {
setUnlocalizedName(name);
setRegistryName(name);
}
}
ItemUranium.java
package items;
public class ItemUranium extends BasicItem {
public ItemUranium() {
super("uranium");
}
}
ClientProxy.java
package proxy;
import items.BasicItem;
import main.Trauma;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
public class ClientProxy extends ServerProxy {
#Override
public void registerClientStuff () {
registerItemModel(Trauma.uranium);
}
public static void registerItemModel(BasicItem item) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Trauma.MODID + ":" + item.getRegistryName(), "inventory"));
}
}
ServerProxy.java
package proxy;
public class ServerProxy {
public void registerClientStuff() {}
}
uranium.json
{
"parent": "item/generated",
"textures": {
"layer0": "Trauma:items/uranium"
}
}
uranium.png
ingame
Also I don't know why the item in inventory isn't called uranium...
I spent two hours on fixing the problem and it didn't help so it would be really nice if somebody of you may help me.
Thanks :)
Don't use the Model Mesher:
The model mesher is Vanilla (Mojang) code and using it correctly has always been finicky and unreliable, failing if you called it too early and failing if you called it too late. So Forge added the ModelLoader class to resolve that problem.
Replace this line:
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(...)
With this line:
ModelLoader.setCustomModelResourceLocation(...)
The ... contents are identical.
Second, depending on what version of Minecraft you're using, you should...:
Stop using GameRegistry.Register
Instead use the RegistryEvent.Register<T> events (where <T> will be <Block> to register blocks, <Item> to register items, etc)
Register your models in the ModelRegistryEvent and no where else.
This event is #SideOnly(CLIENT) and can be subscribed to in your client proxy, avoiding the need to forward references through your proxy class. Eg. I do it like this, where lines 197-199 is the most common scenario needed, where the array is populated during the item registration event. The rest of that method handles the custom state mappers and custom mesh definitions that are used by only a handful of items/blocks and not relevant here.
Include your Mod ID in your unlocalized name. The best way to do this would be setUnlocalizedName(getRegistryName().toString());
See also the Forge documentation on events.
I am trying to add a texture to an item, yet the texture just doesn't appear. I have the texture made, and in the right file directory, but while in game it doesn't display. Thus, I think it's an error in my code.
For the whole class file, see below:
package Moonstone;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;
#Mod(modid = "ms", name = "Moonstone", version = "1.0")
public class MoonstoneMain {
public static Item moonstone;
#EventHandler
public void preInit(FMLPreInitializationEvent event) {
//All init
moonstone = new Moonstone().setUnlocalizedName("Moonstone").setTextureName("moonstone").setMaxStac kSize(64);
GameRegistry.registerItem(moonstone, moonstone.getUnlocalizedName().substring(5));
}
#EventHandler
public void init(FMLInitializationEvent event) {
//Proxy, TileEntity, entity, GUI and packet registering
}
#EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
public static CreativeTabs tabMoonstone = new CreativeTabs("tabMoonstone"){
#Override
public Item getTabIconItem(){
return new ItemStack(Items.stick).getItem();
}
};
}
For just the item, look below-
moonstone = new Moonstone().setUnlocalizedName("Moonstone").setTextureName("moonstone").setMaxStackSize(64);// I have tried with ms:moonstone and without, both don't work.
GameRegistry.registerItem(moonstone, moonstone.getUnlocalizedName().substring(5));
Recommended changes but not necessary:
First:
When registering the item you should remove the .substring(5),
having this in will name the item "Moons" instead of "Moonstone".
Second:
unlocalized names should always be lowercase and should be formatted
as modid_itemname
Third:
Package names should be lowercase, package moonstone
Fourth:
Your should make a Refstrings.java file and put the modid, version and name in it
package Moonstone
public RefStrings{
public static String NAME = "Moonstone";
public static String MODID = "ms";
public static String VERSION = "1.0";
}
Necessary changes:
Your setTextureName should be passed "ms:moonstone"
You didn't post your folder structure but it should look like this:
src/main/java/Moonstone/MoonstoneMain.java
src/main/resources/assests/ms/textures/items/moonstone.png
it is possible that some of the recommend changes will be what fixes the problem, minecraft can be a bit finicky with naming.
import java.sql.SQLException;
import java.util.ArrayList;
public class UserSearchJB {
public UserSearchJB(){
System.out.println("UserSearchJB");
}
public ArrayList searchRecords(UserDTO udto) throws SQLException{
UserSearchDAO usdao = new UserSearchDAO();
ArrayList list = usdao.searchRecords(udto);
return list;
}
}
//This is the code for javabean using struts flow.
This is for model to transfer the data one component to another component
What is the problem in this program i think it is a basic program in which import two spacial package import java.sql.SQLException; and
import java.util.ArrayList;
I am making a Craftbukkit plugin that has a message in the player count list, Like HIVE-MC or Omega Realm. I am coding in Ecplise and using ProtocolLib v3.2.0 and Craftbukkit 1.7.2 R0.3. I am new to java and don't understand it much. I do know that everything is imported.
So far, here are the imported methods, code, and the error
Methods:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
Code:
private List<WrappedGameProfile> message = new ArrayList<WrappedGameProfile>();
public void onEnable() {
if(!new File(getDataFolder(),"RESET.FILE").exists()){
try {
getConfig().set("PCMessage",
Arrays.asList(new String[]{"First Line", "Second Line"}));
new File(getDataFolder(),"RESET.FILE").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
saveConfig();
for (String str : getConfig().getStringList("PCMessage"))
message.add(new WrappedGameProfile("1", str));
ProtocolLibrary
.getProtocolManager()
.addPacketListener(
new PacketAdapter(
this,ListenerPriority.NORMAL,
Arrays.asList(new PacketType[] {PacketType.Status.Server.OUT_SERVER_INFO}),
new ListenerOptions[] { ListenerOptions.ASYNC })); {
}
}
Error:
Cannot instantiate the type PacketAdapter
As you will see in the Javadocs for PacketAdapeter, it is declared as:
public abstract class PacketAdapter implements PacketListener
abstract means the class is not a full class, and must be implemented as a full class or anonymous class, it cannot be instantiated. You need to find a subclass of PacketAdapter, or make one yourself.
For more information, see the Java Tutorial for Abstract Methods and Classes.
probably a very simple issue related to importing the correct libraries but I cannot seem to find anything to help me.
Basically getting this error when trying to run my code:
"Cannot find a class or type named "DataEntry"
This is my Code here:
//Variables
UnfoldingMap map;
List<Marker>countryMarkers;
HashMap<String, DataEntry> dataEntriesMap;
//Core methods...
void setup() {
size(800, 600);
smooth();
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
//Read in GeoJSON File - Countries
List<Feature> countries = GeoJSONReader.loadData(this, "countries.geo.json");
countryMarkers = MapUtils.createSimpleMarkers(countries);
map.addMarkers(countryMarkers);//Add the countries to the map
//External Data source - CSV file
}
void draw() {
map.draw();
}
//Other methods required...
This is a list of all my Imports
import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.utils.*;
import de.fhpotsdam.unfolding.providers.*;
import processing.opengl.*;
import java.util.List;
import java.util.HashMap;
I am experimenting with GeoSpatial data using Processing and the Unfolding Map Library.
I'd appreciate any help guys.
I am not entirely familiar with the packages you are using but based on examples I've seen, it seems as though you are missing an inner class.
Try updating the code as indicated below noting the DateEntry inner class at the very bottom:
//Variables
UnfoldingMap map;
List<Marker>countryMarkers;
HashMap<String, DataEntry> dataEntriesMap;
//Core methods...
void setup() {
size(800, 600);
smooth();
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
//Read in GeoJSON File - Countries
List<Feature> countries = GeoJSONReader.loadData(this, "countries.geo.json");
countryMarkers = MapUtils.createSimpleMarkers(countries);
map.addMarkers(countryMarkers);//Add the countries to the map
//External Data source - CSV file
}
void draw() {
map.draw();
}
public class DataEntry {
String countryName;
String id;
Integer year;
Float value;
}