So what I'm trying to do is use bukkit and a hashmap to save a player's name and their home location to be able to teleport to later. Currently the User._PlayerHomes hashmap will work, but once the server is shutdown and reloaded there is no file named User.ser and if you try to teleport to a home you previously set there is a lengthy error message I will post here.
[13:20:05 INFO]: Kalenpw issued server command: /khome
[13:20:05 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'khome' in plugin TestPlugin v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.PlayerConnection.handleCommand(PlayerConnection.java:1350) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1185) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_85]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_85]
at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at java.lang.Thread.run(Thread.java:745) [?:1.7.0_85]
Caused by: java.lang.NullPointerException
at org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer.teleport(CraftPlayer.java:457) ~[spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity.teleport(CraftEntity.java:225) ~[spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
at com.Khalidor.testplugin.TestPluginCommandExecutor.onCommand(TestPluginCommandExecutor.java:161) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.9.2.jar:git-Spigot-5a40365-b70058a]
... 15 more
Here is all my relevant code I left out the User.java class and plugin.yml because that doesn't seem to be the issue because it works until the server gets restarted but if that would help let me know and I'll add it:
TestPlugin.java:
//#kalenpw
package com.Khalidor.testplugin;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public final class TestPlugin extends JavaPlugin implements Listener {
MyConfigManager manager;
MyConfig homesConfig;
#Override
public void onEnable() {
// TODO insert logic for when plugin is enabled
getLogger().info("onEable has been invoked!");
getServer().getPluginManager().registerEvents(this, this);
this.getCommand("KHome").setExecutor(new TestPluginCommandExecutor(this));
this.getCommand("KSetHome").setExecutor(new TestPluginCommandExecutor(this));
manager = new MyConfigManager(this);
homesConfig = manager.getNewConfig("Homes.yml");
//Deserialize
try{
FileInputStream fileIn = new FileInputStream("User.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
User._PlayerHomes = (HashMap<String, Location>) in.readObject();
in.close();
fileIn.close();
}
catch(IOException i){
i.printStackTrace();
return;
}
catch(ClassNotFoundException c){
System.out.print("User class not found");
c.printStackTrace();
return;
}
}
#Override
public void onDisable() {
// when plugin is disabled
getLogger().info("onDisable has been invoked");
//Serialize object
try{
FileOutputStream fileOut = new FileOutputStream("User.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(User._PlayerHomes);
out.close();
fileOut.close();
System.out.println("Serialized data has been saved");
}
catch(IOException i){
i.printStackTrace();
}
}
}
TestPluginCommandExecutor.java
//#kalenpw
package com.Khalidor.testplugin;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.google.common.io.Files;
public class TestPluginCommandExecutor implements CommandExecutor {
private final TestPlugin plugin;
// All commands
private final String _KHome = "KHome";
private final String _KSetHome = "KSetHome";
ArrayList<String> _AllCommands = new ArrayList<String>();
// Error Messages
private final String _InvalidArguments = ChatColor.RED + "Error(00): Invalid argument!";
private final String _InvalidExecutor = ChatColor.RED + "Error(01): Can't execute command";
//public static HashMap<String, Location> playerHomes = new HashMap<String, Location>();
public TestPluginCommandExecutor(TestPlugin plugin) {
this.plugin = plugin;// store info
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase(_KHome)) {
if (sender instanceof Player) {
Player player = (Player) sender;
//Location homeLocation = playerHomes.get(player.getName());
Location homeLocation = User._PlayerHomes.get(player.getName());
player.teleport(homeLocation);
player.sendMessage("You were teleported home!");
return true;
}
}
if (cmd.getName().equalsIgnoreCase(_KSetHome)) {
if (sender instanceof Player) {
Player player = (Player) sender;
//playerHomes.put(player.getName(), player.getLocation());
//homesConfig.
player.sendMessage("Set your home!");
User._PlayerHomes.put(player.getName(), player.getLocation());
// //Save home to file
// Path playerHomesFile = Paths.get("PlayerHomes.txt");
// String playerName = player.getName();
// String playerX = String.valueOf(player.getLocation().getX());
// String playerY = String.valueOf(player.getLocation().getY());
// String playerZ = String.valueOf(player.getLocation().getZ());
//
//
// //List<String> playerInfo = Arrays.asList(playerName, playerX, playerY, playerZ);
// ArrayList<String> playerInfo = new ArrayList<String>();
// playerInfo.add(playerName);
//
//
// //Files.write(playerHomesFile, playerInfo, Charset.forName("UTF-8"));
// //Files.write(playerHomesFile, playerInfo, Charset.forName("UTF-8"), StandardOpenOption.APPEND);
return true;
}
}
sender.sendMessage(_InvalidExecutor);
return false;
}
}
Thanks for the help! I think I included all the relevant details but if anything is missing or you need clarification let me know and I'll edit.
Edit: The exception when trying to serilize locations:
[14:13:20 WARN]: at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
[14:13:20 WARN]: at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
[14:13:20 WARN]: at java.util.HashMap.writeObject(HashMap.java:1129)
[14:13:20 WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[14:13:20 WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[14:13:20 WARN]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[14:13:20 WARN]: at java.lang.reflect.Method.invoke(Method.java:606)
[14:13:20 WARN]: at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1030)
[14:13:20 WARN]: at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495)
[14:13:20 WARN]: at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
[14:13:20 WARN]: at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
[14:13:20 WARN]: at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
[14:13:20 WARN]: at com.Khalidor.testplugin.TestPlugin.onDisable(TestPlugin.java:90)
[14:13:20 WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:294)
[14:13:20 WARN]: at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:364)
[14:13:20 WARN]: at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:424)
[14:13:20 WARN]: at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:417)
[14:13:20 WARN]: at org.bukkit.craftbukkit.v1_9_R1.CraftServer.disablePlugins(CraftServer.java:340)
[14:13:20 WARN]: at net.minecraft.server.v1_9_R1.MinecraftServer.stop(MinecraftServer.java:454)
[14:13:20 WARN]: at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:595)
[14:13:20 WARN]: at java.lang.Thread.run(Thread.java:745)
class Location, which you were trying to serialize, is not Serializable, and so you cannot simply dump it to file (as you yourself have found out here)
Your options are either to make Location serializable (if you can and it makes sense. i dont know this API), or serialize something else that is serializable in its place and then upon reading that something else convert that information to a Location.
Related
I am fairly new to Java and programming Minecraft plugins. I would like the chat listener to check it the player's name is in the config and then set the display name to that, but if the player's name is not in the config, then I would like it to just set the players name.
This is my Chat Listener:
package me.purp.servercore.listeners;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import me.purp.servercore.Main;
import me.purp.servercore.utils.Utils;
public class ServerChat implements Listener
{
private Main plugin;
public ServerChat(Main plugin)
{
Bukkit.getPluginManager().registerEvents(this, plugin);
}
#EventHandler
public void Chat(AsyncPlayerChatEvent event)
{
String message = event.getMessage();
Player player = event.getPlayer();
if (!plugin.getConfig().contains(player.getName())) {
event.setFormat(Utils.color("&7" + player.getDisplayName() + " &7&l» &r" + message));
} else if (plugin.getConfig().contains(player.getName())) {
event.setFormat(Utils.color("&7" + plugin.getConfig().getString(player.getName()) + " &7&l» &r" + message));
}
}
}
This is my nickname class:
package me.purp.servercore.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import me.purp.servercore.Main;
import me.purp.servercore.utils.Utils;
public class PlayerNick implements CommandExecutor
{
private Main plugin;
public PlayerNick(Main plugin)
{
this.plugin = plugin;
plugin.getCommand("nick").setExecutor(this);
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
FileConfiguration config = plugin.getConfig();
if (!(sender instanceof Player))
{
sender.sendMessage(Utils.color(config.getString("PlayerEntityFalse")));
return true;
}
Player player = (Player) sender;
if (player.hasPermission("core.nick"))
{
if (args.length == 0)
{
player.sendMessage(Utils.color("&cYou cannot have a blank nickname!"));
return true;
}
String nick = "";
for (String arg : args)
{
nick += arg + " ";
}
player.sendMessage(Utils.color("&7Your nickname is now: " + nick));
config.set(player.getName(), nick);
plugin.saveConfig();
}
return false;
}
}
This is my error:
Could not pass event AsyncPlayerChatEvent to Core v0.2
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:482) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at net.minecraft.server.v1_12_R1.PlayerConnection.chat(PlayerConnection.java:1319) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1257) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at net.minecraft.server.v1_12_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
at java.lang.Thread.run(Unknown Source) [?:?]
Caused by: java.lang.NullPointerException
at me.purp.servercore.listeners.ServerChat.Chat(ServerChat.java:29) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
... 11 more
Like said in the comment from Carlos under this post:
You haven't set this.plugin = plugin in your ServerChat class.
Caused by: java.lang.NullPointerException
at me.purp.servercore.listeners.ServerChat.Chat(ServerChat.java:29)
At line 29:
if (!plugin.getConfig().contains(player.getName())) {
so either
plugin or
plugin.getConfig() or
player
is null. Try to print out these variables and tell us which one is null.
My toughts:
Maybe you dont have your config saved with saveDefaultConfig() in the onEnable method. plugin shouldn't be null because then there should be a problem at the constructor when registering the listener. Also the player normally isn't null so the problem should be at the config.
I have written a code which will play music when a link on a webpage is found.
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javafx.application.*;
// * #author Archit
public abstract class WebCrawl extends Application{
public static void main(String[] args) throws IOException {
Application.launch(args);
int a=0;
try {
Document doc = Jsoup.connect("https://in.bookmyshow.com/ranchi").get();
org.jsoup.select.Elements links = doc.select("a");
for (Element e: links) {
if ((e.attr("abs:href").equals("https://in.bookmyshow.com/ranchi/movies/fan/ET00025074"))) {
try {
File f = new File("/Users/Archit/Documents/Music/campbell.wav");
Media hit = new Media(f.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
} catch(Exception ex) {
System.out.println("Exception");
}
}
}
}
The error I am getting is this:
Exception in Application constructor java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class webcrawl.WebCrawl
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application webcrawl.WebCrawl
A window seems to open when I run the application but is automatically closed and this error appears.
I would really appreciate the help. Thank you.
You are starting an application from the WebCrawl class using Application.launch(String[]), so launch tries to create a WebCrawl instance, which it can't, since WebCrawl is abstract.
BTW: Placing code after the Application.launch call won't work, since after Application.launch is finished, the JavaFX platform will already have exited.
You can read about the application lifecycle in the Life-cycle section of the Application javadoc.
You need to call the code form the start method or later.
You can find a tutorial for a simple JavaFX application here: https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm
I am currently stuck with the following prob. The JAR & Pi4J Lib gets executed on a RasPi B+. I've been searching the web for hours without a result. Curiously looking forward to your reponses and support ;-)
Stacktrace:
Exception in thread "main" java.lang.RuntimeException: Unable to open GPIO direction interface for pin [1]: No such file or directory
at com.pi4j.wiringpi.GpioUtil.export(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.export(RaspiGpioProvider.java:108)
at com.pi4j.io.gpio.impl.GpioPinImpl.export(GpioPinImpl.java:158)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionPin(GpioControllerImpl.java:517)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:669)
at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:681)
at com.test.RemoteImpl.fahreVorwaerts(RemoteImpl.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:178)
at sun.rmi.transport.Transport$1.run(Transport.java:175)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(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.fahreVorwaerts(Unknown Source)
at com.client.RMIClient.main(RMIClient.java:19)
package com.test;
The Code:
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import com.interf.test.TestRemote;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPin;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinDirection;
import com.pi4j.io.gpio.PinMode;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.trigger.GpioCallbackTrigger;
import com.pi4j.io.gpio.trigger.GpioPulseStateTrigger;
import com.pi4j.io.gpio.trigger.GpioSetStateTrigger;
import com.pi4j.io.gpio.trigger.GpioSyncStateTrigger;
import com.pi4j.io.gpio.event.GpioPinListener;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import com.pi4j.io.gpio.event.PinEventType;
public class RemoteImpl extends UnicastRemoteObject implements TestRemote {
protected RemoteImpl() throws RemoteException {
super();
}
private static final long serialVersionUID = 1L;
#Override
public boolean isloginvalid(String username) throws RemoteException {
if (username.equals("test")) {
return true;
}
return false;
}
#Override
public void fahreVorwaerts(int dauer) throws RemoteException {
System.out.println("----- EXTCMD: VORWAERTS FAHREN "+"("+ dauer +"ms)" + "-----");
// GPIO CODE SECTION BEGINS
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput pin_gpio01 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW);
pin_gpio01.pulse(dauer, true);
System.out.println("----- INFO: VORWAERTS FAHREN ENDE -----");
}
}
Life could have been so much easier if I'd just had a look on the GPIO numbering. There is no GPIO01!
Anyway, now it works by choosing an existing GPIO. Cheers :-)
Raspberry pi 3 B GPIO
pi4j; GPIO Input Error? "Unable to open GPIO edge interface for pin ??: No such file or directory"
-Solution-
Coding; gpio.setShutdownOptions(true) instead of myButton.setShutdownoptions(true) or gpio.shutdown()
Compile; Next, use the following command to compile this example program:
$ javac -classpath .:classes:/opt/pi4j/lib/'*' -d . ListenGpioExample.java
Execute the following command will run this example program:
$ sudo java -classpath .:classes:/opt/pi4j/lib/'*' ListenGpioExample
Run with sudo command
sudo java -jar yourjarname.jar
I'm using GWT and the GWT GoogleMaps API (v3.8.0). I have everything up and running perfectly.
However, I'd like to disable a few of the default features that come with GoogleMaps, such as street names, the ability to click on restaurants, etc. Basically I'd like a very barebones map layer that I add my own custom layers to.
I thought I could do this using Styles. I'm trying to use a MapTypeStyler with visibility off with a MapTypeStyle of whatever type I wanted to disable (in this test case, MapTypeStyle.ROAD).
Here is the test code I'm trying to get running:
package com.test.client;
import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.Document;
import com.google.maps.gwt.client.GoogleMap;
import com.google.maps.gwt.client.LatLng;
import com.google.maps.gwt.client.MapOptions;
import com.google.maps.gwt.client.MapTypeId;
import com.google.maps.gwt.client.MapTypeStyle;
import com.google.maps.gwt.client.MapTypeStyleElementType;
import com.google.maps.gwt.client.MapTypeStyleFeatureType;
import com.google.maps.gwt.client.MapTypeStyler;
public class GwtTest implements EntryPoint {
#Override
public void onModuleLoad() {
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("sensor=false");
Runnable callback = new Runnable() {
public void run() {
createMap();
}
};
AjaxLoader.loadApi("maps", "3", callback, options);
}
public void createMap() {
JsArray<MapTypeStyle> styles = (JsArray<MapTypeStyle>) JsArray.<MapTypeStyle>createArray();
JsArray<MapTypeStyler> roadStylers = (JsArray<MapTypeStyler>) JsArray.<MapTypeStyler>createArray();
MapTypeStyler roadStyler = MapTypeStyler.visibility("off");
roadStylers.push(roadStyler);
MapTypeStyle roadStyle = MapTypeStyle.create();
roadStyle.setStylers(roadStylers);
roadStyle.setFeatureType(MapTypeStyleFeatureType.ROAD); //this is line 43
roadStyle.setElementType(MapTypeStyleElementType.ALL);
styles.push(roadStyle);
MapOptions mapOpts = MapOptions.create();
mapOpts.setZoom(4);
mapOpts.setCenter(LatLng.create(37.09024, -95.712891));
mapOpts.setMapTypeId(MapTypeId.TERRAIN);
mapOpts.setStreetViewControl(false);
mapOpts.setStyles(styles);
final GoogleMap map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);
}
}
However, when I run that, I get an Exception:
14:49:52.756 [ERROR] [gwttest] Uncaught exception escaped
java.lang.ExceptionInInitializerError: null
at com.test.client.GwtTest.createMap(GwtTest.java:43)
at com.test.client.GwtTest$1.run(GwtTest.java:25)
at com.google.gwt.ajaxloader.client.ExceptionHelper.runProtected(ExceptionHelper.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
at com.google.maps.gwt.client.MapTypeStyleFeatureType$.register(MapTypeStyleFeatureType.java:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.maps.gwt.client.MapTypeStyleFeatureType$.create(MapTypeStyleFeatureType.java)
at com.google.maps.gwt.client.MapTypeStyleFeatureType$.<clinit>(MapTypeStyleFeatureType.java:39)
at com.test.client.GwtTest.createMap(GwtTest.java:43)
at com.test.client.GwtTest$1.run(GwtTest.java:25)
at com.google.gwt.ajaxloader.client.ExceptionHelper.runProtected(ExceptionHelper.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:745)
The weird thing is, the Exception seems to be internal to GoogleMaps, so I don't really know what's going on?
Am I doing something obviously dumb with the Styles?
Edit: I've also asked this question on the GWT Forum.
I found one workaround involving writing native JavaScript that bypasses the GoogleMaps GWT API:
package com.test.client;
import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Document;
import com.google.maps.gwt.client.GoogleMap;
import com.google.maps.gwt.client.LatLng;
import com.google.maps.gwt.client.MapOptions;
import com.google.maps.gwt.client.MapTypeId;
public class GwtTest implements EntryPoint {
#Override
public void onModuleLoad() {
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("sensor=false");
Runnable callback = new Runnable() {
public void run() {
createMap();
}
};
AjaxLoader.loadApi("maps", "3", callback, options);
}
public void createMap() {
MapOptions mapOpts = MapOptions.create();
mapOpts.setZoom(4);
mapOpts.setCenter(LatLng.create(37.09024, -95.712891));
mapOpts.setMapTypeId(MapTypeId.TERRAIN);
mapOpts.setStreetViewControl(false);
GoogleMap map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);
styleMap(map);
}
public native void styleMap(GoogleMap map) /*-{
map.set('styles', [
{
"featureType": "road",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "poi",
"stylers": [
{ "visibility": "off" }
]
},{
"stylers": [
{ "invert_lightness": true }
]
}
]);
}-*/;
}
I'd still be curious to find out if there's a pure Java workaround, but if anybody else has this problem, this native approach works. And it has the added bonus that it works directly with JSON you can export from the GoogleMaps Styling Wizard.
I'm trying to serialize a third-party class (which is not serializable) and I'm using xstream to do so.
At first I tried to build some class to see if it goes well and everything worked fine, But when I tried to convert the third-party instance to xml it thorws exceptions.
the code:
import java.util.List;
import java.util.Set;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import vohmm.application.SimpleTagger3;
public class Tagger{
public static void main(String[] args) {
try {
SimpleTagger3 tagger = new SimpleTagger3(args[0]);
XStream xStream = new XStream(new DomDriver());
String tagger_xml = xStream.toXML(tagger);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
the exceptions:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sleepycat/je/DatabaseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getDeclaredMethod(Class.java:2002)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:164)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:148)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.supportsReadObject(SerializationMethodInvoker.java:105)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.isSerializable(SerializableConverter.java:107)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.canConvert(SerializableConverter.java:103)
at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:56)
at com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:498)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:48)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1022)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1011)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:984)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:971)
at NewDemo.main(NewDemo.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ClassNotFoundException: com.sleepycat.je.DatabaseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 56 more
Is there a resone why xstream won't work with SimpleTagger3? Is there any other way to export java object?
Your classloader failed to load a class named 'com.sleepycat.je.DatabaseException'.
Make sure that this class is available. Try Class.forName("com.sleepycat.je.DatabaseException") to test if the class is available.
If not add it to your classpath or load it with a ClassLoader.