- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试从 bukkit(minecraft) 插件中序列化一个 vector 。
这是我要序列化的类:
package net.cerberusstudios.llama.runecraft.neat;
import org.bukkit.util.Vector;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* Created by Josiah on 5/11/2015 based on Runix
*/
public class Vector3 extends Vector implements Externalizable {
private static final long serialVersionUID = 5312566205481472598L;
public static final Vector3 UP = new Vector3(0, 1,0);
public static final Vector3 DOWN = new Vector3(0,-1,0);
public static final Vector3 NORTH = new Vector3(0,0,-1);
public static final Vector3 EAST = new Vector3( 1,0,0);
public static final Vector3 SOUTH = new Vector3(0,0, 1);
public static final Vector3 WEST = new Vector3(-1,0,0);
public static final Vector3 NONE = new Vector3(0,0,0);
//These map to the minecraft block face, such that you're standing on the side they are pointing
public static final Vector3[] facing = {DOWN, UP, EAST, WEST, NORTH, SOUTH};//NORTH, SOUTH, WEST, EAST};
// Runecraft: 0(down) 1(up) 2(east) 3(west) 4(north) 5(south)
//use like this: WorldXYZ point = point.offset(Vector3.facing[point.face])
public static final String[] faceString = {"Down", "Up", "East", "West", "North", "South"};
//Converts a side to the opposite side. This is the same as XOR'ing it with 1.
public static final int[] oppositeSide = new int[]{1, 0, 3, 2, 5, 4};
public static final Vector3[] xzRotationOrder = {Vector3.NORTH, Vector3.EAST, Vector3.SOUTH, Vector3.WEST,};
public static final Vector3[] xyRotationOrder = {Vector3.UP, Vector3.EAST, Vector3.DOWN, Vector3.WEST,};
public static final Vector3[] yzRotationOrder = {Vector3.NORTH, Vector3.UP, Vector3.SOUTH, Vector3.DOWN,};
public static final Vector3[] conductanceNeighbors = {
new Vector3( 0, 1, 0),
new Vector3( 0,-1, 0),
new Vector3( 0, 0,-1),
new Vector3( 1, 0, 0),
new Vector3( 0, 0, 1),
new Vector3(-1, 0, 0),
new Vector3( 1, 1, 0),
new Vector3(-1, 1, 0),
new Vector3( 0, 1, 1),
new Vector3( 0, 1,-1),
new Vector3( 1, 0, 1),
new Vector3(-1, 0, 1),
new Vector3( 1, 0,-1),
new Vector3(-1, 0,-1),
new Vector3( 1,-1, 0),
new Vector3(-1,-1, 0),
new Vector3( 0,-1, 1),
new Vector3( 0,-1,-1)};
public Vector3(int mx, int my, int mz){
this.x = mx;
this.y = my;
this.z = mz;
}
/** Returns a difference vector such that reference + vector = destination */
public Vector3(WorldXYZ reference, WorldXYZ destination){
x = (int) (destination.getX() - reference.getX());
y = (int) (destination.getY() - reference.getY());
z = (int) (destination.getZ() - reference.getZ());
}
public Vector3(Vector face)
{
x = (int) face.getX();
y = (int) face.getY();
z = (int) face.getZ();
}
public String toString(){
return "\"x\":"+x + ", \"y\":" + y + ", \"z\":" + z;
}
public Vector3 multiply(int m) {
return new Vector3(intX()*m, intY()*m, intZ()*m);
}
public int intX() { return (int)x; }
public int intY() { return (int)y; }
public int intZ() { return (int)z; }
/**
* The object implements the writeExternal method to save its contents
* by calling the methods of DataOutput for its primitive values or
* calling the writeObject method of ObjectOutput for objects, strings,
* and arrays.
*
* @param out the stream to write the object to
*
* @throws IOException Includes any I/O exceptions that may occur
* @serialData Overriding methods should use this tag to describe
* the data layout of this Externalizable object.
* List the sequence of element types and, if possible,
* relate the element to a public/protected field and/or
* method of this Externalizable class.
*/
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeDouble(x);
out.writeDouble(y);
out.writeDouble(z);
}
/**
* The object implements the readExternal method to restore its
* contents by calling the methods of DataInput for primitive
* types and readObject for objects, strings and arrays. The
* readExternal method must read the values in the same sequence
* and with the same types as were written by writeExternal.
*
* @param in the stream to read data from in order to restore the object
*
* @throws IOException if I/O errors occur
* @throws ClassNotFoundException If the class for an object being
* restored cannot be found.
*/
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
x = in.readDouble();
y = in.readDouble();
z = in.readDouble();
}
}
我用来测试序列化的代码是:
Object serializeTest = SerializationUtils.clone(new Vector3(1,1,1));
这是我遇到的错误:
[16:48:03] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Runecraft v3.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:209) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInteractManager.java:462) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:693) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_25]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:643) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:598) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:506) [craftbukkit-1.8.jar:git-Bukkit-1092acb]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
Caused by: org.apache.commons.lang.SerializationException: java.lang.ClassNotFoundException: net.cerberusstudios.llama.runecraft.neat.Vector3
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:166) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:193) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.cerberusstudios.llama.runecraft.Runecraft_MAIN.exportFaith(Runecraft_MAIN.java:7119) ~[?:?]
at net.cerberusstudios.llama.runecraft.Runecraft_MAIN.masterRuneFunctionExecute(Runecraft_MAIN.java:5383) ~[?:?]
at net.cerberusstudios.llama.runecraft.Runecraft_MAIN.onRightClick(Runecraft_MAIN.java:442) ~[?:?]
at net.cerberusstudios.llama.runecraft.Runecraft.onPlayerInteract(Runecraft.java:367) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
... 16 more
Caused by: java.lang.ClassNotFoundException: net.cerberusstudios.llama.runecraft.neat.Vector3
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25]
at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_25]
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_25]
at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_25]
at java.io.ObjectInputStream.resolveClass(Unknown Source) ~[?:1.8.0_25]
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) ~[?:1.8.0_25]
at java.io.ObjectInputStream.readClassDesc(Unknown Source) ~[?:1.8.0_25]
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) ~[?:1.8.0_25]
at java.io.ObjectInputStream.readObject0(Unknown Source) ~[?:1.8.0_25]
at java.io.ObjectInputStream.readObject(Unknown Source) ~[?:1.8.0_25]
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:163) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:193) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
at net.cerberusstudios.llama.runecraft.Runecraft_MAIN.exportFaith(Runecraft_MAIN.java:7119) ~[?:?]
at net.cerberusstudios.llama.runecraft.Runecraft_MAIN.masterRuneFunctionExecute(Runecraft_MAIN.java:5383) ~[?:?]
at net.cerberusstudios.llama.runecraft.Runecraft_MAIN.onRightClick(Runecraft_MAIN.java:442) ~[?:?]
at net.cerberusstudios.llama.runecraft.Runecraft.onPlayerInteract(Runecraft.java:367) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit-1.8.jar:git-Bukkit-1092acb]
... 16 more
我环顾四周,似乎找不到类,因为类路径中没有引用它们,我认为这没有多大意义,因为它们来 self 正在处理的项目。
我也在考虑将其转换为 JSON 而不是序列化,这会是更好的方法吗?
最佳答案
老实说,在我看来,一切都比只输出原始对象要好。我使用 XML 使用库 XStream 序列化我的大部分对象.
XStream xstream = new XStream();
System.out.println(xstream.toXML(new Vector3(x,y,z)));
关于java - 反序列化时抛出 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31274731/
我的应用在尝试访问外部依赖项时遇到 NoClassDefFoundError,但仅限于作为 jar 运行时。 使用 Intellij,我有一个带有主类的简单应用程序,其中包含一些对外部依赖项(例如 s
我收到以下异常: java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.server.servlet.ResteasyBootstr
我正在尝试使用eclipse和tomcat调试solr4.6源代码。我收到错误消息:HTTP 状态 500 - {msg=SolrCore 'collection1' 由于初始化失败而不可用:[sch
我是新来的,很抱歉我的英语不好;)。 我尝试使用以下代码在 java 中加载插件 jar: package testprogramm; import java.io.File; import java
我重新安装了 ADT Bundle,因为我在更新 eclipse 后遇到了一些问题。 现在,当我想测试我的应用程序时,出现以下异常: 06-05 10:33:35.770: E/AndroidRunt
我浏览过现有的帖子,这些帖子处理在 Eclipse 中的 Tomcat 下运行 Java Web 应用程序的 ClassNotFoundException。 我无法提供源代码和配置 Artifact
我忙于我的应用一个多星期,突然: 11-12 07:59:17.860 1653-1653/nl.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: ma
我的应用程序有问题,昨天一切正常,但今天我更新了 sdk,现在当我尝试运行我的应用程序时,出现这样的错误 05-21 00:14:19.285: W/dalvikvm(7061): Unable t
我正在阅读 JPA docs在 Spring ,我正在尝试重组我的代码。 我现在所拥有的: BrewerRepository @Repository public class BrewerReposi
我想像 BalusC's example 一样实现 fileUpload . 不幸的是,我已经在努力声明 servlet。 Extensions Filter javax.faces
在某些机器上运行这个小程序不起作用,但在其他机器上它工作得很好。在所有情况下看起来都安装了 JRE 1.6.0_26。 var attributes = {codebase:'http://kas
我将跟随这个非常简单的教程(http://www.tutorialspoint.com/hadoop/hadoop_mapreduce.htm)一起学习,直到我尝试运行Java文件为止,一切运行良好。
我看到了帖子,并按照流程进行了操作。但这没有用。 ClassNotFoundException, while running example job of Hadoop 请帮助我。 创建的 mapre
我尝试在cloudera quickstart vm上为hadoop运行Mahout Kmeans示例。我在这里读link to clouudera block和这里stack overflow po
我有一个mapreduce程序,其中我使用Hcatalog从Hive表'A'中获取带有HcatInputFormat的详细信息,对其进行处理,然后使用HcatOutput格式将其写回到Hive表'B'
我是激发应用程序编程的新手,因此在这里为这个基本的编程而苦苦挣扎。 我有 scala ide 并附加了来自最新 hadoop 和 spark 发行版的相关 jar 文件。我正在使用的只有一个基本的 s
我正在尝试在本地模式下运行Spark示例,但是正在获取以下堆栈跟踪: Exception in thread "main" java.lang.NoClassDefFoundError: org/ap
我有以下代码: // Test TODO remove try { System.out.println(System.getProperties().getPrope
我有以下文件: src/my_proj/myns.clj: (ns my-proj.myns) (defrecord MyRecord [a b c]) 测试/my_proj/myns_test.c
我试图让应用程序动态加载某些类,然后调用启动方法,但问题是,由于 ClassLoader 不同,一个类无法调用另一个类的方法,但是正如我已经用 google 搜索的那样,我用父类创建了两个类加载器。这
我是一名优秀的程序员,十分优秀!