How can I solve this error in Processing using the unfoldingmaps - java

This is my code
import processing.core.PApplet;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.utils.MapUtils;
public class SimpleMapApp extends PApplet {
UnfoldingMap map;
public void setup() {
size(750, 600,P2D);
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
}
public void draw() {
map.draw();
}
}
When i run it throws exception:
Unfolding Map v0.9.6
Using OpenGLMapDisplay with processing.opengl.PGraphics2D
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://a.tiles.wmflabs.org/bw-mapnik/2/2/2.png at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source) at java.net.URL.openStream(Unknown Source) at
processing.core.PApplet.createInputRaw(PApplet.java:7233) at
processing.core.PApplet.createInput(PApplet.java:7201) at
processing.core.PApplet.loadBytes(PApplet.java:7428) at
processing.core.PApplet.loadImage(PApplet.java:5867) at
de.fhpotsdam.unfolding.tiles.TileLoader.getTileFromUrl(Unknown Source)
at de.fhpotsdam.unfolding.tiles.TileLoader.run(Unknown Source) at
java.lang.Thread.run(Unknown Source)

Try changing your map provider.
map = new UnfoldingMap(this, new Google.GoogleMapProvider());

Related

Java RMI Method Call Connection Refused with OpenVPN

Grrr, I feel that this should be so obvious yet I can't find the solution.
For testing purposes I have created a simple Client and Server for an RMI application. I can successfully run the client and server over a local network. I can also successfully run the application when connected through a Windows 10 Built-In VPN connection. However, when connected via an OpenVPN connection I receive a Connection refused to host exception when calling a method (String response = lookup.helloTo(txt); in the Client code) on the remote object returned from the successful call to lookup = (RMIInterface)Naming.lookup("//192.168.10.14/MyServer");.
All my Google searches state that the java.rmi.server.hostname property must be set which I have done in this case. I am thinking that the issue may be between the VPN client IP address (10.8.0.14) and the server IP address (192.168.10.14). I can ping the server IP address and telnet to port 1099 on the server successfully.
Here is my code. I was hoping if someone could see something that I am missing or doing wrong or if I am on the right track regarding the VPN Client IP <=> Server IP.
Remote Interface:
package devel;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RMIInterface extends Remote {
public String helloTo(String name) throws RemoteException;
}
Server:
package devel;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class ServerOperation extends UnicastRemoteObject implements RMIInterface {
private static final long serialVersionUID = 1L;
protected ServerOperation() throws RemoteException {
super();
}
#Override
public String helloTo(String name) throws RemoteException {
System.err.println(name + " is trying to contact!");
return "Server says hello to " + name;
}
public static void main(String[] args) {
try {
java.lang.System.setProperty("java.rmi.server.hostname", "192.168.10.14");
java.rmi.registry.LocateRegistry.createRegistry(1099);
Naming.rebind("//192.168.10.14/MyServer", new ServerOperation());
System.err.println("Server is ready");
} catch(Exception exc) {
System.err.println("Server exception: " + exc.toString());
exc.printStackTrace();
}
}
}
Client:
package devel;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import javax.swing.JOptionPane;
public class ClientOperation {
private static RMIInterface lookup;
public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
lookup = (RMIInterface)Naming.lookup("//192.168.10.14/MyServer");
String txt = JOptionPane.showInputDialog("What is your name?");
String response = lookup.helloTo(txt);
JOptionPane.showMessageDialog(null, response);
}
}
Exception received:
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 192.168.10.14; nested exception is:
java.net.ConnectException: Connection timed out: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.helloTo(Unknown Source)
at devel.ClientOperation.main(ClientOperation.java:17)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 8 more

Unirest throws class not found exception

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/concurrent/FutureCallback
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at iezon.main.WebSocket.getAllApps(WebSocket.java:21)
at iezon.main.Init.(Init.java:16)
at iezon.main.Init.main(Init.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.http.concurrent.FutureCallback
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
My current code is:
package iezon.main;
import org.json.JSONArray;
import org.json.JSONObject;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import iezon.interfaces.options.InterfaceController;
public class WebSocket {
public WebSocket() {
}
public void getAllApps() {
try {
HttpResponse<JsonNode> request = Unirest.get("https://iezontechnologywebapp.000webhostapp.com/api/store/get").asJson();
JSONArray response = request.getBody().getArray();
for (int i = 0; i < response.length(); i++) {
JSONObject object = response.getJSONObject(i);
// TODO: Load apps properly this is just a test dialog to show they loaded
InterfaceController.showDialog(new Object[] {
object.getString("name"),
object.getString("description")
}, "Apps loaded");
}
} catch (UnirestException e) {
e.printStackTrace();
}
}
}
I have tried adding httpclient-4.3.3.jar to the buildpath as well as commons-io-2.5.jar but neither has fixed the issue, I have checked documentation but doesn't say I need any other libraries to run Unirest

Error when trying to load sound using OpenAL in Java

I was watching this tutorial on making games using java and I was on the part where we import music to our game. However, when I try to load the sounds using a method created in this class:
package main;
import java.util.HashMap;
import java.util.Map;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
public class AudioPlayer {
public static Map<String, Sound> soundMap = new HashMap<String, Sound>();
public static Map<String, Music> musicMap = new HashMap<String, Music>();
public static void load(){
try {
soundMap.put("click_sound", new Sound("res/clickSound.ogg"));
musicMap.put("music", new Music("res/background_Music.ogg"));
} catch (SlickException e) {
e.printStackTrace();
}
}
public static Music getMusic(String key){
return musicMap.get(key);
}
public static Sound getSound(String key){
return soundMap.get(key);
}
}
i get an error that says this:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jorbis/Info
at org.newdawn.slick.openal.OggInputStream.<init>(OggInputStream.java:35)
at org.newdawn.slick.openal.OggDecoder.getData(OggDecoder.java:311)
at org.newdawn.slick.openal.SoundStore.getOgg(SoundStore.java:835)
at org.newdawn.slick.openal.SoundStore.getOgg(SoundStore.java:793)
at org.newdawn.slick.Sound.<init>(Sound.java:87)
at main.AudioPlayer.load(AudioPlayer.java:18)
at main.Game.<init>(Game.java:45)
at main.Game.main(Game.java:160)
Caused by: java.lang.ClassNotFoundException: com.jcraft.jorbis.Info
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 8 more
AL lib: (EE) alc_cleanup: 1 device not closed
have I wrote something wrong? i imported the correct external jars and did everything that said in the tutorial. However, I keep getting this error?

How to fix java.lang.VerifyError?

I am doing a project in java called visual speech recognition . while iam trying to run the below code in eclipse indigo..
package main.java.edu.lipreading;
import com.googlecode.javacpp.BytePointer;
import com.googlecode.javacv.cpp.opencv_core;
import main.java.edu.lipreading.vision.AbstractFeatureExtractor;
import main.java.edu.lipreading.vision.NoMoreStickersFeatureExtractor;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.websocket.WebSocket;
import org.eclipse.jetty.websocket.WebSocketHandler;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.logging.Logger;
import static com.googlecode.javacv.cpp.opencv_core.CV_8UC1;
import static com.googlecode.javacv.cpp.opencv_core.cvMat;
import static com.googlecode.javacv.cpp.opencv_highgui.cvDecodeImage;
/**
* Created with IntelliJ IDEA.
* User: Sagi
* Date: 25/04/13
* Time: 21:47
*/
public class WebFeatureExtractor extends Server {
private final static Logger LOG = Logger.getLogger(WebFeatureExtractor.class.getSimpleName());
private final static AbstractFeatureExtractor fe = new NoMoreStickersFeatureExtractor();
public WebFeatureExtractor(int port) {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
addConnector(connector);
WebSocketHandler wsHandler = new WebSocketHandler() {
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
return new FeatureExtractorWebSocket();
}
};
setHandler(wsHandler);
}
/**
* Simple innerclass that is used to handle websocket connections.
*
* #author jos
*/
private static class FeatureExtractorWebSocket implements WebSocket, WebSocket.OnBinaryMessage, WebSocket.OnTextMessage {
private Connection connection;
public FeatureExtractorWebSocket() {
super();
}
/**
* On open we set the connection locally, and enable
* binary support
*/
#Override
public void onOpen(Connection connection) {
LOG.info("got connection open");
this.connection = connection;
this.connection.setMaxBinaryMessageSize(1024 * 512);
}
/**
* Cleanup if needed. Not used for this example
*/
#Override
public void onClose(int code, String message) {
LOG.info("got connection closed");
}
/**
* When we receive a binary message we assume it is an image. We then run this
* image through our face detection algorithm and send back the response.
*/
#Override
public void onMessage(byte[] data, int offset, int length) {
//LOG.info("got data message");
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
bOut.write(data, offset, length);
try {
String result = convert(bOut.toByteArray());
this.connection.sendMessage(result);
} catch (Exception e) {
LOG.severe("Error in facedetection, ignoring message:" + e.getMessage());
}
}
#Override
public void onMessage(String data) {
LOG.info("got string message");
}
}
public static String convert(byte[] imageData) throws Exception {
opencv_core.IplImage originalImage = cvDecodeImage(cvMat(1, imageData.length, CV_8UC1, new BytePointer(imageData)));
List<Integer> points = fe.getPoints(originalImage);
if(points == null)
return "null";
String ans = "";
for (Integer point : points) {
ans += point + ",";
}
return ans;
}
/**
* Start the server on port 999
*/
public static void main(String[] args) throws Exception {
WebFeatureExtractor server = new WebFeatureExtractor(9999);
server.start();
server.join();
}
}
i am getting this error..
Exception in thread "main" java.lang.VerifyError: class org.eclipse.jetty.server.nio.AbstractNIOConnector overrides final method newBuffer.(I)Lorg/eclipse/jetty/io/Buffer;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at main.java.edu.lipreading.WebFeatureExtractor.<init>(WebFeatureExtractor.java:33)
at main.java.edu.lipreading.WebFeatureExtractor.main(WebFeatureExtractor.java:118)
i got dis code from https://github.com/sagioto/LipReading/blob/master/lipreading-core/src/main/java/edu/lipreading/WebFeatureExtractor.java..
can anyone help me plz..
java.lang.VerifyError can happen if you're running against a different version of a library than the code was compiled against.
Looking in the github repository, I see the files are dated 25 April 2013. Apparently, Jetty has received an update during these last 10 months. Find the version of Jetty that was current on that date and try again.

Jena read from turtle fails

I have just imported jena libraries to eclipse to work on rdf-s and it is my first try, but I cannot read a turtle (.ttl) file.
I tried it in the following way:
import java.io.*;
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
public class Simpsons {
public static void main(String[] args) throws IOException {
Model model=ModelFactory.createDefaultModel();
model.read(new FileInputStream("simpsons.ttl"),null);
}
}
The error I get is the following:
Exception in thread "main" org.apache.jena.riot.RiotException: [line: 1, col: 1 ] Content is not allowed in prolog.
at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)
at org.apache.jena.riot.lang.LangRDFXML$ErrorHandlerBridge.fatalError(LangRDFXML.java:252)
at com.hp.hpl.jena.rdf.arp.impl.ARPSaxErrorHandler.fatalError(ARPSaxErrorHandler.java:48)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:209)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.fatalError(XMLHandler.java:239)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.hp.hpl.jena.rdf.arp.impl.RDFXMLParser.parse(RDFXMLParser.java:151)
at com.hp.hpl.jena.rdf.arp.ARP.load(ARP.java:119)
at org.apache.jena.riot.lang.LangRDFXML.parse(LangRDFXML.java:142)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTFactoryImpl$1.read(RDFParserRegistry.java:142)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:859)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:255)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:241)
at org.apache.jena.riot.adapters.RDFReaderRIOT_Web.read(RDFReaderRIOT_Web.java:62)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:253)
at assignment2.Simpsons.main(Simpsons.java:11)
Please help me with some ideas because I have no clue what the problem would be as it's my very first try with Jena. I also got a hint from somewhere that I should do the following: :
It seems that Jena is not so good at discovering the RDF serialisation
used in files by itself, especially for files addressed with an URL. A
solution to this problem is to make a method that gets the file
extension of the filename by the use of string functions and returns
the appropriate RDF serialisation format in Jena’s predefined strings.
You can then use your method both for reading input and writing to file
in the correct serialisation format.
but I don't really understand how should I write that method.
The read method you are using assumes that the input format is RDF/XML.
you need to use one of the other read methods.
So it would be:
public static void main(String[] args) throws IOException {
Model model=ModelFactory.createDefaultModel();
model.read(new FileInputStream("simpsons.ttl"),null,"TTL");
}
Following Program will read and traverse over the TTL file
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.jena.graph.Triple ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.lang.PipedRDFIterator;
import org.apache.jena.riot.lang.PipedRDFStream;
import org.apache.jena.riot.lang.PipedTriplesStream;
public class ReadingTTL
{
public static void main(String... argv) {
final String filename = "yagoTransitiveType2.ttl";
// Create a PipedRDFStream to accept input and a PipedRDFIterator to
// consume it
// You can optionally supply a buffer size here for the
// PipedRDFIterator, see the documentation for details about recommended
// buffer sizes
PipedRDFIterator<Triple> iter = new PipedRDFIterator<>();
final PipedRDFStream<Triple> inputStream = new PipedTriplesStream(iter);
// PipedRDFStream and PipedRDFIterator need to be on different threads
ExecutorService executor = Executors.newSingleThreadExecutor();
// Create a runnable for our parser thread
Runnable parser = new Runnable() {
#Override
public void run() {
// Call the parsing process.
RDFDataMgr.parse(inputStream, filename);
}
};
// Start the parser on another thread
executor.submit(parser);
// We will consume the input on the main thread here
// We can now iterate over data as it is parsed, parsing only runs as
// far ahead of our consumption as the buffer size allows
while (iter.hasNext()) {
Triple next = iter.next();
// Do something with each triple
System.out.println("Subject: "+next.getSubject());
System.out.println("Object: "+next.getObject());
System.out.println("Predicate: "+next.getPredicate());
System.out.println("\n");
}
}
}

Categories