NullPointerException: Attempt to read from null array
See original GitHub issueHello I’m having a problem with dates received from a web service.
when I try to call toString: startDate.toString("EE dd, MMM: HH:mm")
it throws this exception:
java.lang.NullPointerException: Attempt to read from null array
at org.joda.time.tz.CachedDateTimeZone.getInfo(CachedDateTimeZone.java:143)
at org.joda.time.tz.CachedDateTimeZone.getOffset(CachedDateTimeZone.java:103)
at org.joda.time.format.DateTimeFormatter.printTo(DateTimeFormatter.java:722)
at org.joda.time.format.DateTimeFormatter.printTo(DateTimeFormatter.java:535)
at org.joda.time.format.DateTimeFormatter.print(DateTimeFormatter.java:671)
at org.joda.time.base.AbstractDateTime.toString(AbstractDateTime.java:328)
at com.lasalle.mobile.model.TimeSlot.toString(TimeSlot.java:28)
at com.lasalle.mobile.view.adapters.spinner.TimeSlotAdapter.getView(TimeSlotAdapter.java:54)
I deseralize via Gson with the custom deserializer:
public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
// Do not try to deserialize null or empty values
if (json.getAsString() == null || json.getAsString().isEmpty()) {
return null;
}
final DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser();
return fmt.parseDateTime(json.getAsString());
}
The dates sent from my server DO have ISO format, so is not a deseralization related exception.
i.e.: 2016-09-12T10:00:00-0600
As a side note, the problem only occurs when re-running the app. For example, if I make a full clean install, it doesn’t throw that exception. Maybe is a Joda initialization problem?. I hope I can get help, thank you in advance
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
java.lang.NullPointerException: Attempt to read from null array
It happens when you try to use the data that is null. Share.
Read more >Internal NullPointerException: Attempt to read from null array ...
We started getting a lot of reports in Crashlytics about a crash with this stacktrace: Fatal Exception: java.lang.NullPointerException: Attempt to read from ......
Read more >Attempt to read from null array at android.support.v4.widget ...
crash in java.lang.NullPointerException: Attempt to read from null array at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(Unknown Source).
Read more >trying to read from null array (Example) | Treehouse Community
I tried to initilize the array before the startActivty(intent) call but it still gives same message.
Read more >What Is NullPointerException In Java & How To Avoid It
This is another cause of NullPointerException. Here we attempt to access a class member using a null object. We assign the return value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have managed to fix it. The problem was in the serialization, not in GSON but in Kyro. As I’m using PaperDb as a “caché” for the web service results, and It uses Kyro serialization to save the objects.
It didn’t threw any serialization exception, so I thought it was fine, later I found out it requires a JodaTimeSerializer to be set up, which they also provide.
Everything is working fine now, sorry for the misleading issue.
@Dosssik No need to do that, as Paper uses Kyro underhood, so you just add your serializer to Kyro directly.