這裏是我的界面,我從Serializable接口擴展:java.io.NotSerializableException而傳遞接口通過intent.putExtra
public interface InstaListener extends Serializable {
void onSuccess(String response);
void onFailure(int code, String reason);
}
這裏是如何,我傳遞了兩個活動之間的這個監聽器:
InstaListener iListener = new InstaListener() {
@Override
public void onSuccess(String response) {
}
@Override
public void onFailure(int code, String reason) {
}
};
Intent intent = new Intent(activity, Insta.class);
intent.putExtra("email", email);
intent.putExtra("phone", phone);
intent.putExtra("purpose", purpose);
intent.putExtra("amount", amountstr);
intent.putExtra("name", name);
intent.putExtra("env", env);
intent.putExtra("listener", iListener);
activity.startActivity(intent);
這裏的我如何接收Insta班的聽衆。
instaListener = (InstaListener) getIntent().getSerializableExtra("listener");
我已經搜索很多帖子,但沒有解釋爲什麼我得到的錯誤: java.io.NotSerializableException
任何幫助嗎?
編輯 發佈異常和堆棧跟蹤
FATAL EXCEPTION: main
Process: instamojo.testapp, PID: 6785
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = instamojo.library.InstamojoPay$1)
at android.os.Parcel.writeSerializable(Parcel.java:1527)
at android.os.Parcel.writeValue(Parcel.java:1475)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:724)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
at android.os.Bundle.writeToParcel(Bundle.java:1157)
at android.os.Parcel.writeBundle(Parcel.java:764)
at android.content.Intent.writeToParcel(Intent.java:8687)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3271)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1691)
at android.app.Activity.startActivityForResult(Activity.java:4291)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4249)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4603)
at android.app.Activity.startActivity(Activity.java:4563)
at instamojo.library.InstamojoPay.initInstamojo(InstamojoPay.java:61)
at instamojo.library.InstamojoPay.start(InstamojoPay.java:34)
at instamojo.testapp.MainActivity.callInstamojoPay(MainActivity.java:58)
at instamojo.testapp.MainActivity.access$000(MainActivity.java:17)
at instamojo.testapp.MainActivity$1.onClick(MainActivity.java:39)
at android.view.View.performClick(View.java:5669)
at android.view.View$PerformClick.run(View.java:22549)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6290)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.io.NotSerializableException: instamojo.library.InstamojoPay
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1224)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1584)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1549)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1472)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at android.os.Parcel.writeSerializable(Parcel.java:1522)
at android.os.Parcel.writeValue(Parcel.java:1475)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:724)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
at android.os.Bundle.writeToParcel(Bundle.java:1157)
at android.os.Parcel.writeBundle(Parcel.java:764)
at android.content.Intent.writeToParcel(Intent.java:8687)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3271)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1691)
at android.app.Activity.startActivityForResult(Activity.java:4291)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4249)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4603)
at android.app.Activity.startActivity(Activity.java:4563)
at instamojo.library.InstamojoPay.initInstamojo(InstamojoPay.java:61)
at instamojo.library.InstamojoPay.start(InstamojoPay.java:34)
at instamojo.testapp.MainActivity.callInstamojoPay(MainActivity.java:58)
at instamojo.testapp.MainActivity.access$000(MainActivity.java:17)
at instamojo.testapp.MainActivity$1.onClick(MainActivity.java:39)
at android.view.View.performClick(View.java:5669)
at android.view.View$PerformClick.run(View.java:22549)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6290)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
在您的問題中發佈整個異常和堆棧跟蹤。 – EJP
編輯&添加異常和堆棧跟蹤 – user1051505