Class NotFoundException in android.util.ArrayMap inside Intent

I was developing an Android application and in one of the sections passed data using Intent from the DatePicker dialog fragment back to the fragment created using getTargetFragment (). onActivityResult (int targetRequestCode, int resultCode, Intent intent), I add three integers (date, month and year) extracted from the calendar fragment to the transferred intent. Then I read this intent in the onActivityResult () method of the fragment it created. Everything works as it should, and everything is fine, and the dandy and the world are the perfect place to live.

While I was trying to debug the stupid mistake I made, I noticed something interesting. When I expand the content of the intent, I find that my data is in the packet as expected. But I see that there is another object inside the intent called android.util.ArrayMap with size 3.

ArrayMap exception

This size, apparently, corresponds to the amount of data that I set in the intent (I tested it by adding additional dummy parameters). when I expand the contents of the ArrayMap, I see that it throws a ClassNotFoundException. Why do this. The key type is String and the value type is Integer (I put an int, but I don't think it matters, since I added a key and value to String, and it still throws an exception). I expanded the details of ArrayMap, but that doesn't seem to make sense.

Details of the ArrayMap

My questions:

  • Why does this ClassNotFoundException event occur?
  • What is necessary for ArrayMap in the first place?
+2
source share
1 answer

your putExtra values putExtra stored inside the internal Bundle data structure, which happens to be an ArrayMap

Here is its definition declared in source Bundle.java

  // Invariant - exactly one of mMap / mParcelledData will be null // (except inside a call to unparcel) /* package */ ArrayMap<String, Object> mMap = null; 

I assume that it will convert your int into a more general Object class.

ClassNotFoundException can be an IDE / debug problem, since there is no other custom class for this data structure. In addition, you must use the package name prefix in name , as indicated here

 The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll". 
+2
source

Source: https://habr.com/ru/post/977985/


All Articles