java-当我尝试通过意图传递对象时,它使我的应用程序崩溃

java-当我尝试通过意图传递对象时,它使我的应用程序崩溃,第1张

概述当我不故意使用putExtra时,该应用程序运行良好,但是当我使用putExtra并传递对象时,它会崩溃.我还尝试在HumLogController类(我想传递其对象)中实现Serializable.结果也与parceable相同,即它崩溃了.packagecom.example.praduman.humlog;importandroid.app.ActionBar;importa

当我不故意使用putExtra时,该应用程序运行良好,但是当我使用putExtra并传递对象时,它会崩溃.我还尝试在HumLogController类(我想传递其对象)中实现Serializable.结果也与parceable相同,即它崩溃了.

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);    }}

活动日志是:-问题是,当我不使用putExtra时,它不会崩溃.有人可以帮忙..吗?以下是androID studio中的日志猫.
正如我所说,我尝试同时实现Serializable和Parceable,但它们都不起作用.

07-25 11:21:50.294  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ Late-enabling CheckJNI07-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.getChangingConfigurations07-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 ()I07-25 11:21:50.466  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000207-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.getType07-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)I07-25 11:21:50.466  14241-14241/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000207-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.getDrawable07-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 0x000207-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.getDrawableForDensity07-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 0x000207-25 11:21:50.526  14241-14241/com.example.praduman.humlog D/AndroIDRuntime﹕ Shutting down VM07-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.access0(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.access0(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 6ms07-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.getNotificationUri07-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

当我没有在HumLogController中实现Serilizable并仅在通过意图传递对象时将对象强制转换为对象时,会发生上述错误.下面是我也在那里实现Serializable时的HumLogController类的代码.

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;    }}

下面是我在HumLogContoller类中实现可序列化时的日志猫.

07-25 11:42:23.838  23311-23311/? D/dalvikvm﹕ Late-enabling CheckJNI07-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.getNotificationUri07-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 0x000207-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 4ms07-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.getChangingConfigurations07-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 ()I07-25 11:42:24.118  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000207-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.getType07-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)I07-25 11:42:24.126  23311-23311/com.example.praduman.humlog D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000207-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.getDrawable07-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 0x000207-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.getDrawableForDensity07-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 0x000207-25 11:42:24.206  23311-23311/com.example.praduman.humlog D/AndroIDRuntime﹕ Shutting down VM07-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 14ms07-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.access0(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.access0(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.access0(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)

解决方法:

如果您具有类似HumLogController的自定义Serializable类,则必须确保其所有字段也都是Serializable,或者如果您不想对其进行序列化,则将其声明为transient.就您而言,HumLogModel不可序列化.

总结

以上是内存溢出为你收集整理的java-当我尝试通过意图传递对象时,它使我的应用程序崩溃全部内容,希望文章能够帮你解决java-当我尝试通过意图传递对象时,它使我的应用程序崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1079716.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存