A story stuck with NotSerializableException

phenomenon

When I tried to store the Serializable class AAA in an ArrayList and write it out to a file, I got a NotSerializableException. (Of course, all AAA fields are also Serializable)

The code at that time is as follows. (Please forgive me that the code is that ...)

Navigator.java


public class Navigator {
    AppCompatActivity activity;


    public void navigateToFuga(ArrayList<AAA> list) {
        // FugaActivity.Create Intent in createIntent
        //Write hoges to a file and pack the file path into an Intent
        activity.startActivity(FugaActivity.createIntent(activity, list));
    }
}

HogeActivity.java


public void go() {
    navigator.navigateToFuga(new ArrayList<AAA>(){{
        add(bbb.aaa);
    }});
}

Solution

I rewrote the code as follows:

HogeActivity.java


public void go() {
    ArrayList<AAA> list = new ArrayList();
    list.add(bbb.aaa);
    navigator.navigateToFuga(list);
}

Afterword

It is common to pack data in Intent for screen transition of Activity. The app crashed because I put a large amount of unexpected data in the Intent. So, I temporarily responded by the above method, but I was in trouble with an exception. Looking at the debugger,

FugaActivity.The data type of ArrayList received by createIntent is HogeActivity$It was something like 1, so I thought it was a mistake and corrected it, and it worked.


 It took several hours to solve it, so I have to avoid getting caught up in the same problem in the future.

 Even if I checked it with NotSerializableException, it seemed that no one was suffering from the same cause, so I wrote it in the article, but I wonder how I should check it. .. ..


Recommended Posts

A story stuck with NotSerializableException
A little addictive story with def initialize
A story stuck with log output in Docker + Play framework environment
A story packed with Java's standard input Scanner
[PHP] A story about outputting PDF with TCPDF + FPDI
The story of making a reverse proxy with ProxyServlet
A story about trying to get along with Mockito
A story about reducing memory consumption to 1/100 with find_in_batches
A story about developing ROS called rosjava with java
Story of making a task management application with swing, java
A story packed with the basics of Spring Boot (solved)
A story stuck with an error when building Vagrant + Virtulbox CentOS7.8 and creating a shared folder
Create a playground with Xcode 12
Draw a gradient with CAGradientLayer
A story addicted to toString () of Interface proxied with JdkDynamicAopProxy
A confused story about a ternary operator with multiple conditional expressions
The story of the first Rails app refactored with a self-made helper
A story that I struggled to challenge a competition professional with Java
A funny story stuck in a mess when trying to import fx-clj
[Note] A story about changing Java build tools with VS Code
A story of connecting to a CentOS 8 server with an old Ansible
A story about having a hard time aligning a testing framework with Java 6
A story that struggled with the introduction of Web Apple Pay
Create a Vue3 environment with Docker!
Deploy a Docker application with Greengrass
Make a digging maze with Ruby2D
Build a Java project with Gradle
Write a Reactive server with Micronaut
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Make a slideshow tool with JavaFX
Conditional branching with a flowing interface
Throw a PATCH request with HttpURLConnection
Launch a stub server with WireMock
[Rails] Creating a new project with rails new
I made a GUI with Swing
Make a Christmas tree with swift
A really scary (Java anti-pattern) story
Creating a timer app with a muddy
Make a garbage reminder with line-bot-sdk-java
Build a web application with Javalin
Make a list map with LazyMap
Operate a honeypot (Dionaea) with Docker
A little regular expression story Part 2
Draw a pie chart with Chart.js
Exception handling with a fluid interface
Get stuck in a Java primer
Create exceptions with a fluid interface
Create a Maven project with a command
A little troublesome story in Groovy
A memorandum with NTP (chrony) set
Make a typing game with ruby
The story of making a game launcher with automatic loading function [Java]