question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException: Attempt to read from null array

See original GitHub issue

Hello 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:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
diegoRodriguezAguilacommented, Sep 6, 2016

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.

0reactions
diegoRodriguezAguilacommented, Dec 17, 2018

@Dosssik No need to do that, as Paper uses Kyro underhood, so you just add your serializer to Kyro directly.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found