I am trying to create an xml file from jsp.
This is my GenerateXml.java file. It is located in sap_workshop/WEB-INF/src/MyPackage.
package MyPackage;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.lang.*;
import java.io.Serializable;
public class GenerateXml implements Serializable{
private String wDate="a";
public void setDate(String wDate) {
this.wDate = wDate;
}
public String getDate() {
return this.wDate;
}
}
I have a workshop_html_snippet.jsp file in sap_workshop folder.
The file is:
<?xml version="1.0" encoding="UTF-8"?>
<%# page contentType="text/xml %>
<jsp:useBean id="xml" scope="page" class="sap_workshop/WEB-INF/src/MyPackage.GenerateXml"/>
<Workshop>
<Scheduled>
<WorkshopDate><% out.print(xml.getDate()); %></WorkshopDate>
</Scheduled>
</Workshop>
When i compile the java file, it doesnot show any errors but when i execute i get following errors:
Exception in thread "main" java.lang.NoClassDefFoundError: GenerateXml (wrong name: MyPackage/GenerateXml)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Thank you.
You need to define your bean like so
<jsp:useBean id="xml" scope="page" class="MyPackage.GenerateXml"/>
and ensure that your class is in your classpath.
The stacktrace is as a result of the malformed bean name. The format is:
package.BeanName
Related
[04:48:05 ERROR]: Could not load 'plugins\HelloWorld.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.spoonle.helloworld.Main'
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:66) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:152) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: java.lang.ClassNotFoundException: me.spoonle.helloworld.Main
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_211]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_211]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_211]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_211]
at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_211]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
... 7 more
I keep getting this error while loading my plugin onto my test server.
(I did check the other posts and they didn't help me)
plugin.yml file:
name: HelloWorld
version: 1.0
author: Spoonle
main: me.spoonle.helloworld.Main
commands:
hello:
alias: [hi]
do I need to add something? Those are spaces and not tabs. I saw that using TAB can break the yml file so I used spaces instead.
Code:
package me.spoonle.helloworld.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.spoonle.helloworld.Main;
public class HelloCommand implements CommandExecutor {
private Main plugin;
public HelloCommand(Main plugin) {
this.plugin = plugin;
plugin.getCommand("hello").setExecutor(this);
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may execute this command!");
return true;
}
Player p = (Player) sender;
if (p.hasPermission("hello.use")) {
p.sendMessage("Hello!");
return true;
} else {
p.sendMessage("You do not have permissions to use this command!");
}
return false;
}
}
This is just what I want the plugin to do. I don't know if this helps but its here if you need it.
Why can't I load my plugin??
Edit: I fixed the invalid plugin.yml. Now it is saying it can't find the main class. As stated above in the plugin.yml code, its me.spoonle.helloworld.Main and thats where my main file is located. How do I fix that now??
Is the plugin.yml file in the same folder as the Main file?
If so, you just have to write
main: Main
Your main class must extend JavaPlugin
Your plugin.yml must state "main: " and then your main class.
There should be a class called Main in the package me.spoonle.helloworld. If so, your main class is in the correct location.
Also, it is not good practice to use Main as your main class. Use the name of your program instead.
Example
Main:
package me.spoonle.helloworld;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
// Initialise HelloCommand here and set the executor of "hello" command
}
#Override
public void onDisable() {
}
}
Plugin.yml:
name: HelloWorld
version: 1.0
author: Spoonle
main: me.spoonle.helloworld.Main
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 making a small plugin framework for a program in Java.
Basically GRPluginManager.loadPlugins() loops trough all jar files in a directory, then reads the name of the Main-class of this plugin from a specific file inside of the jar and loads it into the classpath. After that it calls the enable() method of this plugin-Main-class (which extends GRPlugin).
However, it doesn't work. It looks like the loading of the plugin-Main-class works fine and only the parent class (GRPlugin) can not be found. But it definitely exists.
GRPlugin.java
package io.github.grengine.core.plugins;
public class GRPlugin {
public void enable(){
}
public void disable(){
}
}
GRPluginManager.java
package io.github.grengine.core.plugins;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.yaml.snakeyaml.Yaml;
import io.github.grengine.JarUtils;
import io.github.grengine.Log;
import io.github.grengine.Main;
public class GRPluginManager {
private static final String PLUGIN_PATH = Main.main.getDataFolder()+File.separator+"storage"+File.separator+"plugins";
private ArrayList<GRPlugin> plugins = new ArrayList<GRPlugin>();
public ArrayList<GRPlugin> loadPlugins() throws Exception{
File filePath = new File(PLUGIN_PATH);
File files [] = filePath.listFiles();
//Iterate over files in the plugin directory
for(File file:files){
if(file.isFile()){
Log.Info("Reading "+file);
ZipFile zipFile = new ZipFile(file);
String fullyQualifiedName = null;
String plname = null;
String plversion = null;
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry ze = (ZipEntry) entries.nextElement();
if(ze.getName().equals("gre"+File.separator+"ext.yml")){
Yaml yaml = new Yaml();
InputStream is = zipFile.getInputStream(ze);
Map<?, ?> map = (Map<?, ?>) yaml.load(is);
fullyQualifiedName = (String) map.get("main");
plname = (String) map.get("name");
plversion = (String) map.get("version");
}
}
zipFile.close();
Log.Info("Enabling "+plname+" "+plversion+" ...");
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { new URL("file:"+file) });
Class<?> clazz = classLoader.loadClass(fullyQualifiedName);
GRPlugin pl = (GRPlugin) clazz.newInstance();
pl.enable();
Log.Info("Enabling "+plname+" "+plversion+" ...");
}else {
//skip folders
continue;
}
}
return plugins;
}
}
And the Main class of the plugin (the class extending GRPlugin) / Main.java
package io.github.plutos;
import io.github.grengine.Log;
import io.github.grengine.core.plugins.GRPlugin;
public class Main extends GRPlugin{
#Override
public void enable() {
Log.Info("ENABLED");
}
#Override
public void disable() {
Log.Info("DISABLED");
}
}
Here is the stacktrace:
java.lang.NoClassDefFoundError: io/github/grengine/core/plugins/GRPlugin
at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_05]
at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[?:1.8.0_05]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[?:1.8.0_05]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455) ~[?:1.8.0_05]
at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[?:1.8.0_05]
at java.net.URLClassLoader$1.run(URLClassLoader.java:367) ~[?:1.8.0_05]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[?:1.8.0_05]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_05]
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[?:1.8.0_05]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_05]
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:798) ~[?:1.8.0_05]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_05]
at io.github.grengine.core.plugins.GRPluginManager.loadPlugins(GRPluginManager.java:82) ~[?:?]
at io.github.grengine.Main.onEnable(Main.java:56) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-core.jar:git-Spigot-c5146ba-c637b93]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:418) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:382) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:337) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:256) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:528) [spigot-core.jar:git-Spigot-c5146ba-c637b93]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_05]
Caused by: java.lang.ClassNotFoundException: io.github.grengine.core.plugins.GRPlugin
at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[?:1.8.0_05]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[?:1.8.0_05]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_05]
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[?:1.8.0_05]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_05]
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:798) ~[?:1.8.0_05]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_05]
... 25 more
I just can't find a solution for this problem, I already tried different ClassLoaders (ClassLoader.getSystemClassLoader() and GRPlugin.class.getClassLoader()) ...
Can you tell what i am doing wrong? If you need more information, feel free to ask!
Thanks in advance,
fusionlightcat
If you don't set a parent classloader to your custom classloader, the system classloader will be used as parent by default.
It seems that in your environment GRPlugin is loaded by a descendant of the system classloader and hence the error.
Use this instead:
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { new URL("file:"+file) }, GRPlugin.class.getClassLoader());
You can see plugin system implementation in ipscan open source project. Here is start points for exploration:
main Plugin interface. Any of plugins in ipscan must implement it.
PluginLoader class is your GRPluginManager analog. It loads plugins from different places (in project jar, external jars etc.) Look here implementation of PluginClassLoader which extends URLClassLoader and loads classes from jar files.
feeders folder with some inproject plugins which implemented Plugin interface.
UPDATE: also you can reuse for your plugin system standard java.util.ServiceLoader or some alternative solution
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 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.