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;
}
Related
Below, I am trying to change the value of the Path object there using the setSoundPath() method. I cannot find any documentation to say this is possible.
I am trying to create a class that will create a copy of a file at a specified path and put the copy in the specified folder. I need to be able to change the name of the path though, because I want to create the sound object with an initial placeholder file path.
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.io.IOException;
import javafx.beans.property.StringProperty;
import javafx.beans.property.SimpleStringProperty;
class Scratch {
public static class Sound extends Object{
private Path there;
StringProperty tests = new SimpleStringProperty(this, "test", "");
public Sound(){
this.there = Paths.get("C:\\Users\\HNS1Lab.NETWORK\\Videos\\JuiceWRLD.mp3");
}
public void setSoundPath(String SoundPath) {
this.tests.setValue(SoundPath);
this.there = Paths.get(this.tests.toString());
}
}
public static void main(String[] args) {
Sound test = new Sound();
test.setSoundPath("C:\\Users\\HNS1Lab.NETWORK\\Music\\Meowing-cat-sound.mp3");
test.copySound();
System.out.println("Path: " + test.getSoundPath().toString());
}
}
They are immutable:
Implementations of this interface are immutable and safe for use by
multiple concurrent threads.
(from: https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html)
You can create new Path objects that point to your path.
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?
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.
I know C++ at a decent level and I am trying to learn java. This will be a silly question but I cannot figure out how to import a .java file into another. I am at Eclipse IDE and in my project I have two files:
FileReader.java
Entry.java
I want to import the Entry.java in the other file but no matter what I do I get an error. Can you help me? Thx in advance.
FileReader.java :
import java.io.*;
class FileReader {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World");
Entry a(10,"a title","a description");
a.print();
}
}
Entry.java:
public class Entry{
int ID;
String title;
String description;
public Entry(int id, String t,String d){
ID=id;
title=t;
description=d;
}
public void print(){
System.out.println("ID:"+ID);
System.out.println("Title:"+title);
System.out.println("Description:"+description);
}
}
At this state I get an error that Entry cannot be resolved as a variable. So I believe that it is related to the import.
Firstly
Entry a(10,"a title","a description");
should be
Entry a = new Entry (10,"a title","a description");
If Entry is in the same package then you will not need to import it.
If Entry is in a different package, say com.example then you will need to do
Either
import com.example.Entry;
or
import com.example.*;
The second import will import all classes in the com.example package - usually not such a good thing.
You need new Entry
The new keyword creates the new object
Entry a = new Entry(10,"a title","a description")
a.print();
An Entry object is created with the a reference with the above instantiation.
For the import part of your question, if two files are in the same package, no import is needed. If you Entry class was in a different package than your FileReader class, then you would need to import mypackage.Entry
Try
Entry a = new Entry(/*args*/);
And if you need to import the class, then use the absolute name (package+class) and put it after import above the class declaration
import com.example.you.Entry;
In Eclipse you can do Ctrl+Shift+O to resolve all imports.
I used the hadoop apache to create a counting Bloom Filter. However I get a NullPointerException when I am trying to add keys in it. I tried to change the class structure in many ways but still I get the same result.
Here is the code I did:
package package_name;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.hadoop.util.bloom.*;
public class CBF {
public static CountingBloomFilter CBF = new CountingBloomFilter();
public static void countingFilter (ArrayList<byte[]> CBF_Keys) throws IOException{
CBF_Keys= Keys.keyStringArray;
Iterator<byte[]> iter = CBF_Keys.iterator();
while (iter.hasNext()) {
byte[] temp = iter.next();
Key hadoop_key = new Key(temp, 2.0);
CBF.add(hadoop_key);
}
}
}
problem is CBF = new CountingBloomFilter(). We should use CountingBloomFilter(int vectorSize, int nbHash, int hashType) instead here, otherwise the HashFunction will not be constructed in parent class Filter.