我有两个maven项目,项目A内容一些可序列化的模型对象,项目B是GWT项目.现在我想使用项目A中的一些对象来进行项目B中客户端和服务器之间的RPC调用.
所以这就是我所做的:
GWT项目B xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='Index'>
<inherits name='com.google.gwt.user.User' />
<inherits name='com.projectA.Models' />
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<entry-point class='com.projectB.client.Index' />
<source path='client' />
<source path='shared' />
</module>
Run Code Online (Sandbox Code Playgroud)
Java对象项目A xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User"/>
<source path="./" />
</module>
Run Code Online (Sandbox Code Playgroud)
我仍然得到"没有源代码可用于类型com.projectA.Object;你忘了继承一个必需的模块吗?" 消息=(
(POM依赖设置!)
您好我试图将图像位置保存到sreen到内部存储但是我得到一个NotSerializableException.我去搜索并发现问题是Bitmap不是为了在这个链接上 序列化问题序列化Drawable我从来没有真正理解他如何修复问题抛出这个例子.如果有人可以解释他如何修复他的NotSerializableException并帮助我与我的相处,我将不胜感激
这是我的Elememt课程
public class Element extends main implements Serializable{
private int mX;
private int mY;
int location2 ;
Matrix elementlocation;
private Bitmap mBitmap;
Canvas canvas2;
public Element(Resources res, int x, int y) {
location2 =item3;
mBitmap = BitmapFactory.decodeResource(res, location2);
mX = x - mBitmap.getWidth() / 2;
mY = y - mBitmap.getHeight() / 2;
}
public Element(){
}
public void doDraw2(Canvas canvas) {
elementlocation=new Matrix();
elementlocation.postTranslate(mX,mY);
canvas2=canvas;
canvas2.drawBitmap(mBitmap, elementlocation,null);
}
public void setelementlocation(float num1,float num2){
elementlocation=new Matrix();
elementlocation.postTranslate(num1,num2);
} …Run Code Online (Sandbox Code Playgroud) 我正在写一个班级来跟踪锦标赛的比赛数据.我想将这个类存储到一个文件中,所以我正在使用ObjectInputStream.我写的类实现了Serializable.我得到了一个EOFException,而且我在SO和其他地方找到的解决方案都没有解决这个问题.
我的文件编写者是:
public void writeToFile(String path) {
File f = new File(path);
if(f.exists()) f.delete();
try {
OutputStream fileOut = new FileOutputStream(path);
OutputStream bufferOut = new BufferedOutputStream(fileOut);
ObjectOutput output = new ObjectOutputStream(bufferOut);
output.writeObject(this);
} catch(IOException e) {}
}
Run Code Online (Sandbox Code Playgroud)
我的文件阅读器是:
public static DivisionDataFTC readFromFile(String path) {
try {
InputStream fileIn = new FileInputStream(path);
InputStream bufferIn = new BufferedInputStream(fileIn);
ObjectInput input = new ObjectInputStream(bufferIn);
System.out.println(input.read());
} catch(Exception e) {
System.out.println(path);
e.printStackTrace();
}
if(1==1) throw new Error("Could not read DivisionDataFTC …Run Code Online (Sandbox Code Playgroud) 我收到此错误:
FATAL EXCEPTION: main
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = game.Level)
at android.os.Parcel.writeSerializable(Parcel.java)
at android.os.Parcel.writeValue(Parcel.java)
at android.os.Parcel.writeMapInternal(Parcel.java)
at android.os.Bundle.writeToParcel(Bundle.java)
at android.os.Parcel.writeBundle(Parcel.java)
at android.content.Intent.writeToParcel(Intent.java)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java)
at android.app.Instrumentation.execStartActivity(Instrumentation.java)
at android.app.Activity.startActivityForResult(Activity.java)
at android.app.Activity.startActivityForResult(Activity.java)
at android.app.Activity.startActivity(Activity.java)
at android.app.Activity.startActivity(Activity.java)
at menu.AreaAdapter$1.onClick(AreaAdapter.java:93)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.NotSerializableException: menu.AreaActivity
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368) …Run Code Online (Sandbox Code Playgroud) 我试图用JAXB序列化ArrayList并失败.这是因为elementData被标记为瞬态?
为什么ArrayList实现Serializable Inferface并且它的数据是瞬态的?
我尝试序列化Serializables的ArrayList:
JAXBElement<ArrayList> jaxbElement = new JAXBElement<ArrayList>(new QName(ArrayList.class.getSimpleName()), ArrayList.class, allEntities);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(jaxbElement, System.out);
Run Code Online (Sandbox Code Playgroud)
如何通过JAXB执行此操作?
我有一个用户定义的类Message,我想在客户端和服务器之间传递它的对象.
Message类如下:
import java.io.Serializable;
public class Message implements Serializable
{
String CorS;
int data_id;
int status_id;
Integer value;
boolean withdraw;
public Message()
{
CorS = null;
data_id = 0;
status_id = 0;
value = 0;
withdraw = false;
}
public Message(String CorS, int data_id, int status_id, Integer value)
{
this.CorS = CorS;
this.data_id = data_id;
this.status_id = status_id;
this.value = value;
}
public Message(boolean withdraw)
{
this.withdraw = withdraw;
}
}
Run Code Online (Sandbox Code Playgroud)
将对象发送到服务器的客户端代码如下:
Socket s = null;
ObjectInputStream in = null; …Run Code Online (Sandbox Code Playgroud) 我这次使用的是Serializable Interface.我想将ArrayList从一个活动传递到另一个活动,但它给了我这个错误"无法编组值",代码是,
//发送活动:
public class LogIn extends Activity implements OnClickListener
{
ProgressDialog pd;
ImageButton logIn,registr;
EditText userName,Password;
public static String usrName,passwrd;
String TAG=LogIn.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
userName=(EditText)findViewById(R.id.logIn_etuserName);
Password=(EditText)findViewById(R.id.logIn_etpaswrd);
logIn=(ImageButton)findViewById(R.id.logIn_B_logIn);
registr=(ImageButton)findViewById(R.id.logIn_B_registration);
logIn.setOnClickListener(this);
registr.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
String respns="";
switch (v.getId())
{
case R.id.logIn_B_logIn:
try
{
usrName=userName.getText().toString();
passwrd=Password.getText().toString();
if(usrName.contentEquals("") && passwrd.contentEquals(""))
{
Toast.makeText(getApplicationContext(), "Enter userName",Toast.LENGTH_LONG).show();
}
// else if(passwrd.contentEquals(""))
// {
// Toast.makeText(getApplicationContext(), "Enter password",Toast.LENGTH_LONG).show();
// }
else
{
pd=ProgressDialog.show(LogIn.this, "LogIn", "Logging");
new …Run Code Online (Sandbox Code Playgroud) 我正在使用ObjectOutputStream将我的对象保存到.dat文件.我的问题是,如果我改变我的对象的源代码(例如我添加一个方法(getter))输入流无法加载数据并告诉我一个错误Serializable:有可能解决这个问题吗?.dat如果我更改源代码,我必须每次都生成新文件.
使用此方法:( 不要看对象类型 - 返回值)保存
public void saveToFile(HeaderOfMapTeachStructure hm, String nameOfFile) {
try (ObjectOutputStream os = new ObjectOutputStream(
new FileOutputStream(nameOfFile + "." + this.TYPE_OF_FILE))) {
os.writeObject(hm);
} catch (IOException e) {
System.out.println("Error: " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
加载
public MapStandard loadFromFileMS(String nameOfFile) {
MapStandard hm = null;
InputStream inputStreaminputStream
= getClass().getClassLoader().
getResourceAsStream("data/" + nameOfFile + ".data");
try {
try (ObjectInputStream is = new ObjectInputStream(inputStreaminputStream)) {
hm = (MapStandard) is.readObject();
}
} …Run Code Online (Sandbox Code Playgroud) 我已经尝试了所有在StackOverflow上发现的该问题的解决方案,但是尽管如此,我还是无法解决。我有一个“ MainObj”对象,该对象实例化了“ Recommendation”对象。当我调用“ recommendationProducts”方法时,总是出现错误。这是该方法的代码:
def recommendationProducts(item: Int): Unit = {
val aMatrix = new DoubleMatrix(Array(1.0, 2.0, 3.0))
def cosineSimilarity(vec1: DoubleMatrix, vec2: DoubleMatrix): Double = {
vec1.dot(vec2) / (vec1.norm2() * vec2.norm2())
}
val itemFactor = model.productFeatures.lookup(item).head
val itemVector = new DoubleMatrix(itemFactor)
//Here is where I get the error:
val sims = model.productFeatures.map { case (id, factor) =>
val factorVector = new DoubleMatrix(factor)
val sim = cosineSimilarity(factorVector, itemVector)
(id, sim)
}
val sortedSims = sims.top(10)(Ordering.by[(Int, Double), Double] {
case (id, similarity) => …Run Code Online (Sandbox Code Playgroud) 我正在使用.NET Framework 4.7开发C#库。
我想将类ProductionOrderXmlFile转换为XML文件:
[Serializable]
public class Level
{
[XmlElement("Id")]
public byte Id { get; set; }
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("CodeType")]
public byte CodeType { get; set; }
[XmlElement("CodeSourceType")]
public byte CodeSourceType { get; set; }
[XmlElement("HelperCodeType")]
public byte HelperCodeType { get; set; }
[XmlElement("HelperCodeSourceType")]
public byte HelperCodeSourceType { get; set; }
[XmlElement("PkgRatio")]
public int PkgRatio { get; set; }
}
[Serializable]
public class VarData
{
[XmlElement("VariableDataId")]
public string VariableDataId { get; set; …Run Code Online (Sandbox Code Playgroud) serializable ×10
java ×4
android ×3
apache-spark ×1
bundle ×1
c# ×1
client ×1
exception ×1
file ×1
file-io ×1
filereader ×1
gwt ×1
ioexception ×1
maven ×1
module ×1
object ×1
parcelable ×1
scala ×1
sockets ×1
transient ×1
xml ×1