0

NullPointerException が発生する理由がわかりません。ここで何が欠けていますか?

public class CustomJourneyUserInformation {
    public IJourneyDetails journeyDetails;
    public IUserDetails userDetails;
    public ISubscribeJourney subscribedToJourneys;
}

IJourneyDetails、IUserDetails、ISubscribeJourney はすべてインターフェイスです

別のアクティビティで、私は呼び出しています

private CustomJourneyUserInformation[] allJourneyDetails;
    allJourneyDetails = new CustomJourneyUserInformation[subscribedToJourneys.length];
    if (providerDetails[i] != null)
>>> allJourneyDetails[i].journeyDetails = providerDetails[i];
    if (userDetails[i] != null)
    allJourneyDetails[i].userDetails = userDetails[i];
    if (subscribedToJourneys[i] != null)
        allJourneyDetails[i].subscribedToJourneys = subscribedToJourneys[i];

>>>> でマークされた行でヌルポインタ例外が発生しています

allJourneyDetails[i]ここではnullだと確信しています。

4

2 に答える 2

6

It looks like allJourneyDetails[i] is null, since the array is still filled with null after initialization.

Did you expect creating the array to fill the array with non-null values? That's not how it works in Java.

于 2012-12-13T19:51:59.213 に答える
2
allJourneyDetails = new CustomJourneyUserInformation[subscribedToJourneys.length];

する必要があります

allJourneyDetails = new CustomJourneyUserInformation[providerDetails.length];

それも; しかし、@LouisWassermanは正しいです

于 2012-12-13T19:53:05.833 に答える