When I try to pass an object with intent it resets my application

The app works well when I don't use putExtra with intent, but when I use putExtra and pass an object it crashes. I also tried to implement Serializable in the HumLogController class (the object I want to pass). Also, the results are the same with passive ones, i.e. failure.

package com.example.praduman.humlog;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import com.parse.Parse;
import java.io.Serializable;

public class HomeActivity extends ActionBarActivity {

    private HumLogController humLogController;
    private Intent logInActivityIntent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        humLogController = new HumLogController();      


        logInActivityIntent = new Intent(this , LogInActivity.class);
        logInActivityIntent.putExtra("my object", (Serializable) humLogController);
        startActivity(logInActivityIntent);
    }


}

      

Activity Log: - The thing is, it doesn't crash when I don't use putExtra. Can anyone help ..? Below is the log cat in android studio. As I said, I tried to implement both Serializable and Parceable but doesn't work.

07-25 11:21:50.294  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ Late-enabling CheckJNI
07-25 11:21:50.462  14241-14241/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
07-25 11:21:50.466  14241-14241/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 440: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
07-25 11:21:50.466  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:21:50.466  14241-14241/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
07-25 11:21:50.466  14241-14241/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 462: Landroid/content/res/TypedArray;.getType (I)I
07-25 11:21:50.466  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:21:50.474  14241-14241/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
07-25 11:21:50.474  14241-14241/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 403: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
07-25 11:21:50.474  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:21:50.474  14241-14241/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
07-25 11:21:50.474  14241-14241/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 405: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
07-25 11:21:50.478  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:21:50.526  14241-14241/com.example.praduman.humlog D/AndroidRuntime﹕ Shutting down VM
07-25 11:21:50.526  14241-14241/com.example.praduman.humlog W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c47648)
07-25 11:21:50.530  14241-14241/com.example.praduman.humlog E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praduman.humlog/com.example.praduman.humlog.HomeActivity}: java.lang.ClassCastException: com.example.praduman.humlog.HumLogController cannot be cast to java.io.Serializable
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassCastException: com.example.praduman.humlog.HumLogController cannot be cast to java.io.Serializable
            at com.example.praduman.humlog.HomeActivity.onCreate(HomeActivity.java:32)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
07-25 11:21:50.534  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ GC_FOR_ALLOC freed 291K, 4% free 9017K/9336K, paused 6ms, total 6ms
07-25 11:21:50.558  14241-14256/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.database.Cursor.getNotificationUri, referenced from method com.parse.ParseSQLiteCursor.getNotificationUri
07-25 11:21:50.558  14241-14256/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve interface method 488: Landroid/database/Cursor;.getNotificationUri ()Landroid/net/Uri;
07-25 11:21:50.558  14241-14256/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002

      

The above errors occur when I don't implement Serilizable in HumLogController and just throw an object into an object, going through the intent. Below is the code for the HumLogController class when I also implement Serializable.

package com.example.praduman.humlog;

import java.io.Serializable;

/**
 * Created by Praduman on 23/07/2015.
 */
public class HumLogController implements Serializable{
   private HumLogModel humLogModel ;
    private String username;
    private String password;
    private String userType;

    public HumLogController() {
        this.humLogModel = new HumLogModel();
    }
    public void createNewUser(){
        humLogModel.createNewUser(getUsername(), getPassword());
    }

    public void setUserEssentials(String username,String password, String userType){
        setUsername(username); setPassword(password); setUserType(userType);
    }

    public void setUsername(String username){
        this.username = username;
    }
    public void setPassword(String password){
        this.password = password;
    }
    public void setUserType(String userType){
        this.userType = userType;
    }

    public String getUsername(){
        return username;
    }
    public String getPassword(){
        return password;
    }
    public String getUserType(){
        return userType;
    }
}

      

The local code when I implement the serializable in the HumLogContoller class is below.

07-25 11:42:23.838  23311-23311/? D/dalvikvm﹕ Late-enabling CheckJNI
07-25 11:42:24.058  23311-23330/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.database.Cursor.getNotificationUri, referenced from method com.parse.ParseSQLiteCursor.getNotificationUri
07-25 11:42:24.058  23311-23330/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve interface method 488: Landroid/database/Cursor;.getNotificationUri ()Landroid/net/Uri;
07-25 11:42:24.058  23311-23330/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
07-25 11:42:24.102  23311-23331/com.example.praduman.humlog D/dalvikvm﹕ GC_FOR_ALLOC freed 283K, 4% free 9025K/9336K, paused 4ms, total 4ms
07-25 11:42:24.118  23311-23311/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
07-25 11:42:24.118  23311-23311/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 440: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
07-25 11:42:24.118  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:42:24.122  23311-23311/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
07-25 11:42:24.126  23311-23311/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 462: Landroid/content/res/TypedArray;.getType (I)I
07-25 11:42:24.126  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:42:24.130  23311-23311/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
07-25 11:42:24.130  23311-23311/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 403: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
07-25 11:42:24.130  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:42:24.150  23311-23311/com.example.praduman.humlog I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
07-25 11:42:24.150  23311-23311/com.example.praduman.humlog W/dalvikvm﹕ VFY: unable to resolve virtual method 405: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
07-25 11:42:24.150  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-25 11:42:24.206  23311-23311/com.example.praduman.humlog D/AndroidRuntime﹕ Shutting down VM
07-25 11:42:24.206  23311-23311/com.example.praduman.humlog W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c47648)
07-25 11:42:24.222  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ GC_FOR_ALLOC freed 381K, 5% free 9147K/9560K, paused 13ms, total 14ms
07-25 11:42:24.222  23311-23311/com.example.praduman.humlog E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.praduman.humlog/com.example.praduman.humlog.HomeActivity}: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.praduman.humlog.HumLogController)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.praduman.humlog.HumLogController)
            at android.os.Parcel.writeSerializable(Parcel.java:1285)
            at android.os.Parcel.writeValue(Parcel.java:1233)
            at android.os.Parcel.writeMapInternal(Parcel.java:591)
            at android.os.Bundle.writeToParcel(Bundle.java:1646)
            at android.os.Parcel.writeBundle(Parcel.java:605)
            at android.content.Intent.writeToParcel(Intent.java:6831)
            at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1927)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
            at android.app.Activity.startActivityForResult(Activity.java:3390)
            at android.app.Activity.startActivityForResult(Activity.java:3351)
            at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
            at android.app.Activity.startActivity(Activity.java:3587)
            at android.app.Activity.startActivity(Activity.java:3555)
            at com.example.praduman.humlog.HomeActivity.onCreate(HomeActivity.java:33)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.io.NotSerializableException: com.example.praduman.humlog.HumLogModel
            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)
            at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
            at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
            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 android.os.Parcel.writeSerializable(Parcel.java:1280)
            at android.os.Parcel.writeValue(Parcel.java:1233)
            at android.os.Parcel.writeMapInternal(Parcel.java:591)
            at android.os.Bundle.writeToParcel(Bundle.java:1646)
            at android.os.Parcel.writeBundle(Parcel.java:605)
            at android.content.Intent.writeToParcel(Intent.java:6831)
            at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1927)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
            at android.app.Activity.startActivityForResult(Activity.java:3390)
            at android.app.Activity.startActivityForResult(Activity.java:3351)
            at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
            at android.app.Activity.startActivity(Activity.java:3587)
            at android.app.Activity.startActivity(Activity.java:3555)
            at com.example.praduman.humlog.HomeActivity.onCreate(HomeActivity.java:33)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

      

+3


source to share


1 answer


If you have your own Serializable class, such as HumLogController, you must ensure that all of its fields are Serializable as well, or declare them transient

if you don't want to serialize them. HumLogModel

Not Serializable in your case .



+3


source







All Articles