我正在后端工作,在这里我将一个对象保存在数据库中,然后我启动新活动,但它显示错误。目前,我没有在活动之间传递任何数据,但仍然得到错误。我的代码是
MessageThreads newThread = new MessageThreads();
newThread.setUser1(user);
newThread.setUser2(currentUser);
ChatMessages message = new ChatMessages();
message.setCreator(currentUser);
message.setText("Hello");
List<ChatMessages> list = new ArrayList<>();
list.add(message);
newThread.setMessages(list);
Backendless.Data.of(MessageThreads.class).save(newThread, new AsyncCallback<MessageThreads>() {
@Override
public void handleResponse(MessageThreads response) {
progressDialog.dismiss();
response.setDialogName(user.getProperty("name").toString());
Intent intent = new Intent(getContext(), SingleMessageActivity.class);
// intent.putExtra("threadId", response.getObjectId());
// intent.putExtra("name", response.getDialogName());
startActivity(intent);
}
@Override
public void handleFault(BackendlessFault fault) {
makeToast("error in loading messages");
}
});
这是我的错误跟踪
Process: com.example.mubtadanaqvi.stunexus, PID: 30625
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.backendless.BackendlessUser)
at android.os.Parcel.writeSerializable(Parcel.java:1323)
at android.os.Parcel.writeValue(Parcel.java:1271)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:148)
at android.os.Parcel.writeTypedArray(Parcel.java:1140)
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:564)
at android.os.Parcel.writeParcelable(Parcel.java:1292)
at android.os.Parcel.writeValue(Parcel.java:1211)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2755)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3313)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.NotSerializableException: java.lang.Object
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1366)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:981)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1076)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1406)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1673)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1519)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1483)
at android.os.Parcel.writeSerializable(Parcel.java:1318)
at android.os.Parcel.writeValue(Parcel.java:1271)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:148)
at android.os.Parcel.writeTypedArray(Parcel.java:1140)
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:564)
at android.os.Parcel.writeParcelable(Parcel.java:1292)
at android.os.Parcel.writeValue(Parcel.java:1211)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2755)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3313)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
chatMessages模型:
package com.example.mubtadanaqvi.stunexus;
import com.backendless.BackendlessUser;
import com.stfalcon.chatkit.commons.models.IMessage;
import com.stfalcon.chatkit.commons.models.IUser;
import java.util.Date;
import weborb.service.ExcludeProperties;
@ExcludeProperties(propertyNames = {"createdAt", "id","user"})
public class ChatMessages implements IMessage
{
private java.util.Date created;
private String objectId;
private String text;
private java.util.Date updated;
private String ownerId;
private BackendlessUser creator;
private String id;
private IUser user;
private Date date;
public java.util.Date getCreated()
{
return created;
}
public String getObjectId()
{
return objectId;
}
public void setText( String text )
{
this.text = text;
}
public java.util.Date getUpdated()
{
return updated;
}
public String getOwnerId()
{
return ownerId;
}
public BackendlessUser getCreator()
{
return creator;
}
public void setCreator( BackendlessUser creator )
{
this.creator = creator;
}
public String getText()
{
return text;
}
@Override
public String getId() {
return getObjectId();
}
public void setId(String id){
this.id=id;
}
@Override
public IUser getUser() {
DialogAuthor user = new DialogAuthor();
user.setId(getObjectId());
user.setName(getCreator().getProperty("name").toString());
user.setAvtar(null);
return user;
}
public void setUser(IUser user){
this.user=user;
}
@Override
public Date getCreatedAt() {
return getCreated();
}
public void setCreatedAt(Date d){
this.date=d;
}
}//class
Backendless User类是内置的,下面是代码:
/*
* ********************************************************************************************************************
* <p/>
* BACKENDLESS.COM CONFIDENTIAL
* <p/>
* ********************************************************************************************************************
* <p/>
* Copyright 2012 BACKENDLESS.COM. All Rights Reserved.
* <p/>
* NOTICE: All information contained herein is, and remains the property of Backendless.com and its suppliers,
* if any. The intellectual and technical concepts contained herein are proprietary to Backendless.com and its
* suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret
* or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden
* unless prior written permission is obtained from Backendless.com.
* <p/>
* ********************************************************************************************************************
*/
package com.backendless;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public final class BackendlessUser implements Serializable
{
private final Map<String, Object> properties = new HashMap<String, Object>();
public static final String PASSWORD_KEY = "password";
public static final String EMAIL_KEY = "email";
public static final String ID_KEY = "objectId";
public BackendlessUser()
{
}
/**
* Returns a COPY of user's properties
* (this means if you modify the return value, actual user properties won't be modified)
*
* @return a COPY of this user's properties
*/
public Map<String, Object> getProperties()
{
return new HashMap<String, Object>( properties );
}
public void setProperties( Map<String, Object> properties )
{
synchronized( this )
{
this.properties.clear();
putProperties( properties );
}
}
public void putProperties( Map<String, Object> properties )
{
synchronized( this )
{
this.properties.putAll( properties );
}
}
public Object getProperty( String key )
{
synchronized( this )
{
if( properties == null )
return null;
return properties.get( key );
}
}
public void setProperty( String key, Object value )
{
synchronized( this )
{
properties.put( key, value );
}
}
public String getObjectId()
{
return getUserId();
}
public String getUserId()
{
Object result = getProperty( ID_KEY );
return result == null ? null : String.valueOf( result );
}
public void setPassword( String password )
{
setProperty( PASSWORD_KEY, password );
}
public String getPassword()
{
Object result = getProperty( PASSWORD_KEY );
return result == null ? null : String.valueOf( result );
}
public void setEmail( String email )
{
setProperty( EMAIL_KEY, email );
}
public String getEmail()
{
Object result = getProperty( EMAIL_KEY );
return result == null ? null : String.valueOf( result );
}
public void clearProperties()
{
synchronized( this )
{
properties.clear();
}
}
public Object removeProperty( String key )
{
return properties.remove( key );
}
@Override
public boolean equals( Object o )
{
if( this == o )
return true;
if( o == null || getClass() != o.getClass() )
return false;
BackendlessUser that = (BackendlessUser) o;
if( !properties.equals( that.properties ) )
return false;
return true;
}
private Object marker;// = new Object();
@Override
public int hashCode()
{
Set<Object> refCache = new HashSet<Object>( );
return hashCode( refCache );
}
private int hashCode(Set<Object> refCache)
{
if( marker != null )
return 0;
else
marker = new Object();
if(refCache.contains( marker ))
return 0;
refCache.add( marker );
int hashCode = 0;
for( Object value : properties.values() )
{
if(value == null)
continue;
if(value instanceof BackendlessUser)
hashCode += ((BackendlessUser) value).hashCode( refCache );
else
hashCode += value.hashCode();
}
return hashCode;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( "BackendlessUser{" );
for( Map.Entry<String, Object> property : properties.entrySet() )
{
sb.append( property.getKey() ).append( "=" ).append( property.getValue() ).append( ", " );
}
sb.delete( sb.length() - 2, sb.length() );
sb.append( "}" );
return sb.toString();
}
}