addValueEventListener for firebase read data returning null on Android 6.02019 Community Moderator ElectionHow do I obtain crash-data from my Android application?How do I pass data between Activities in Android application?How do I get extra data from intent on Android?Firebase addValueEventListener sometimes returns a null DataSnapshotgetColor(int id) deprecated on Android 6.0 Marshmallow (API 23)Difference between addValueEventListener() and addListenerForSingleValueEvent() of firebaseFirebase read addValueEventListener onDataChange value nullFirebase addValueEventListener not getting triggeredReading Firebase data returns null AndroidUpdated global variables does not reflect inside ValueEventListener's onCancelled method

Power Strip for Europe

Signed and unsigned numbers

Help find my computational error for logarithms

For which categories of spectra is there an explicit description of the fibrant objects via lifting properties?

Why do we say ‘pairwise disjoint’, rather than ‘disjoint’?

Why couldn't the separatists legally leave the Republic?

Does a difference of tense count as a difference of meaning in a minimal pair?

I reported the illegal activity of my boss to his boss. My boss found out. Now I am being punished. What should I do?

After `ssh` without `-X` to a machine, is it possible to change `$DISPLAY` to make it work like `ssh -X`?

Can we track matter through time by looking at different depths in space?

What can I do if someone tampers with my SSH public key?

How do electrons receive energy when a body is heated?

Did Amazon pay $0 in taxes last year?

Can I negotiate a patent idea for a raise, under French law?

Can I use a violin G string for D?

Specifying a starting column with colortbl package and xcolor

Getting the || sign while using Kurier

What's the 'present simple' form of the word "нашла́" in 3rd person singular female?

Haman going to the second feast dirty

How can I manipulate the output of Information?

Expressing logarithmic equations without logs

Do I really need to have a scientific explanation for my premise?

Is it safe to abruptly remove Arduino power?

School performs periodic password audits. Is my password compromised?



addValueEventListener for firebase read data returning null on Android 6.0



2019 Community Moderator ElectionHow do I obtain crash-data from my Android application?How do I pass data between Activities in Android application?How do I get extra data from intent on Android?Firebase addValueEventListener sometimes returns a null DataSnapshotgetColor(int id) deprecated on Android 6.0 Marshmallow (API 23)Difference between addValueEventListener() and addListenerForSingleValueEvent() of firebaseFirebase read addValueEventListener onDataChange value nullFirebase addValueEventListener not getting triggeredReading Firebase data returns null AndroidUpdated global variables does not reflect inside ValueEventListener's onCancelled method










1















I have the below class. When the readJson method is called, I am getting null pointer exception in Android 6.0. How do I fix the NPE? It is working fine on most of the devices and versions, but it seems to be failing on Android 6.0. I have searched for answers, but I couldn't find the problem in the code.Im getting NPE when trying to access variables of Screens.



public class UserRepository 

private static UserRepository instance = null;
final String TAG = UserRepository.class.getName();
public Resorts resortsData;
public AppSettings appSettingsData;

@Inject
public Resources resources;

public static synchronized UserRepository getInstance()
if (instance == null)
instance = new UserRepository();

return instance;


public void readJson()

FirebaseDatabase database = FirebaseDatabase.getInstance();
String lang = Locale.getDefault().getLanguage();
DatabaseReference myRef = database.getReference(lang);

myRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
// This method is called once with the initial value and again
// whenever data at this location is updated.
resortsData = dataSnapshot.getValue(Resorts.class);
boolean hasChild = dataSnapshot.hasChild("appSettings");
if (hasChild)
DataSnapshot appSettings = dataSnapshot.child("appSettings");
appSettingsData = appSettings.getValue(AppSettings.class);
Log.e("NAG",appSettingsData.screens.toString());



//Resorts resortsData = resort.getValue(Resorts.class);


@Override
public void onCancelled(DatabaseError error)
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());

);




public class AppSettings
public ArrayList<ApiEndpoints> apiEndpoints;
public Screens screens;
public GlobalStrings globalStrings;


public class Screens
public RegisterStay registerStay;
public CalendarScreen calendar;
public RegisterError registerError;
public BookingNumber bookingNumber;
public InDestDashboard inDestDashboard;
public PreDestDashboard preDestDashboard;
public LocalExcursions localExcursions;
public PreDestMenu preDestMenu;
public InDestMenu inDestMenu;
public EmailSubscribe emailSubscribe;
public UnregisteredLanding unregisteredLanding;



Error message



Caused by java.lang.NullPointerException: Attempt to read from field 'com.royalton.mobileapp.common.repositories.models.appSettings.screens.Screens com.royalton.mobileapp.common.repositories.models.appSettings.AppSettings.screens' on a null object reference
at com.royalton.mobileapp.base.AppModule.providesEmailSubscribeScreen(AppModule.java:192)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:19)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:8)









share|improve this question
























  • At which line of code are you getting NPE and please also add your database structure.

    – Alex Mamo
    Mar 6 at 14:59











  • @AlexMamo Im getting NPE when trying to access the screens variable.

    – Nagendra Kumar
    Mar 6 at 15:23











  • At this line Log.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.

    – Alex Mamo
    Mar 6 at 15:24















1















I have the below class. When the readJson method is called, I am getting null pointer exception in Android 6.0. How do I fix the NPE? It is working fine on most of the devices and versions, but it seems to be failing on Android 6.0. I have searched for answers, but I couldn't find the problem in the code.Im getting NPE when trying to access variables of Screens.



public class UserRepository 

private static UserRepository instance = null;
final String TAG = UserRepository.class.getName();
public Resorts resortsData;
public AppSettings appSettingsData;

@Inject
public Resources resources;

public static synchronized UserRepository getInstance()
if (instance == null)
instance = new UserRepository();

return instance;


public void readJson()

FirebaseDatabase database = FirebaseDatabase.getInstance();
String lang = Locale.getDefault().getLanguage();
DatabaseReference myRef = database.getReference(lang);

myRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
// This method is called once with the initial value and again
// whenever data at this location is updated.
resortsData = dataSnapshot.getValue(Resorts.class);
boolean hasChild = dataSnapshot.hasChild("appSettings");
if (hasChild)
DataSnapshot appSettings = dataSnapshot.child("appSettings");
appSettingsData = appSettings.getValue(AppSettings.class);
Log.e("NAG",appSettingsData.screens.toString());



//Resorts resortsData = resort.getValue(Resorts.class);


@Override
public void onCancelled(DatabaseError error)
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());

);




public class AppSettings
public ArrayList<ApiEndpoints> apiEndpoints;
public Screens screens;
public GlobalStrings globalStrings;


public class Screens
public RegisterStay registerStay;
public CalendarScreen calendar;
public RegisterError registerError;
public BookingNumber bookingNumber;
public InDestDashboard inDestDashboard;
public PreDestDashboard preDestDashboard;
public LocalExcursions localExcursions;
public PreDestMenu preDestMenu;
public InDestMenu inDestMenu;
public EmailSubscribe emailSubscribe;
public UnregisteredLanding unregisteredLanding;



Error message



Caused by java.lang.NullPointerException: Attempt to read from field 'com.royalton.mobileapp.common.repositories.models.appSettings.screens.Screens com.royalton.mobileapp.common.repositories.models.appSettings.AppSettings.screens' on a null object reference
at com.royalton.mobileapp.base.AppModule.providesEmailSubscribeScreen(AppModule.java:192)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:19)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:8)









share|improve this question
























  • At which line of code are you getting NPE and please also add your database structure.

    – Alex Mamo
    Mar 6 at 14:59











  • @AlexMamo Im getting NPE when trying to access the screens variable.

    – Nagendra Kumar
    Mar 6 at 15:23











  • At this line Log.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.

    – Alex Mamo
    Mar 6 at 15:24













1












1








1








I have the below class. When the readJson method is called, I am getting null pointer exception in Android 6.0. How do I fix the NPE? It is working fine on most of the devices and versions, but it seems to be failing on Android 6.0. I have searched for answers, but I couldn't find the problem in the code.Im getting NPE when trying to access variables of Screens.



public class UserRepository 

private static UserRepository instance = null;
final String TAG = UserRepository.class.getName();
public Resorts resortsData;
public AppSettings appSettingsData;

@Inject
public Resources resources;

public static synchronized UserRepository getInstance()
if (instance == null)
instance = new UserRepository();

return instance;


public void readJson()

FirebaseDatabase database = FirebaseDatabase.getInstance();
String lang = Locale.getDefault().getLanguage();
DatabaseReference myRef = database.getReference(lang);

myRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
// This method is called once with the initial value and again
// whenever data at this location is updated.
resortsData = dataSnapshot.getValue(Resorts.class);
boolean hasChild = dataSnapshot.hasChild("appSettings");
if (hasChild)
DataSnapshot appSettings = dataSnapshot.child("appSettings");
appSettingsData = appSettings.getValue(AppSettings.class);
Log.e("NAG",appSettingsData.screens.toString());



//Resorts resortsData = resort.getValue(Resorts.class);


@Override
public void onCancelled(DatabaseError error)
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());

);




public class AppSettings
public ArrayList<ApiEndpoints> apiEndpoints;
public Screens screens;
public GlobalStrings globalStrings;


public class Screens
public RegisterStay registerStay;
public CalendarScreen calendar;
public RegisterError registerError;
public BookingNumber bookingNumber;
public InDestDashboard inDestDashboard;
public PreDestDashboard preDestDashboard;
public LocalExcursions localExcursions;
public PreDestMenu preDestMenu;
public InDestMenu inDestMenu;
public EmailSubscribe emailSubscribe;
public UnregisteredLanding unregisteredLanding;



Error message



Caused by java.lang.NullPointerException: Attempt to read from field 'com.royalton.mobileapp.common.repositories.models.appSettings.screens.Screens com.royalton.mobileapp.common.repositories.models.appSettings.AppSettings.screens' on a null object reference
at com.royalton.mobileapp.base.AppModule.providesEmailSubscribeScreen(AppModule.java:192)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:19)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:8)









share|improve this question
















I have the below class. When the readJson method is called, I am getting null pointer exception in Android 6.0. How do I fix the NPE? It is working fine on most of the devices and versions, but it seems to be failing on Android 6.0. I have searched for answers, but I couldn't find the problem in the code.Im getting NPE when trying to access variables of Screens.



public class UserRepository 

private static UserRepository instance = null;
final String TAG = UserRepository.class.getName();
public Resorts resortsData;
public AppSettings appSettingsData;

@Inject
public Resources resources;

public static synchronized UserRepository getInstance()
if (instance == null)
instance = new UserRepository();

return instance;


public void readJson()

FirebaseDatabase database = FirebaseDatabase.getInstance();
String lang = Locale.getDefault().getLanguage();
DatabaseReference myRef = database.getReference(lang);

myRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
// This method is called once with the initial value and again
// whenever data at this location is updated.
resortsData = dataSnapshot.getValue(Resorts.class);
boolean hasChild = dataSnapshot.hasChild("appSettings");
if (hasChild)
DataSnapshot appSettings = dataSnapshot.child("appSettings");
appSettingsData = appSettings.getValue(AppSettings.class);
Log.e("NAG",appSettingsData.screens.toString());



//Resorts resortsData = resort.getValue(Resorts.class);


@Override
public void onCancelled(DatabaseError error)
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());

);




public class AppSettings
public ArrayList<ApiEndpoints> apiEndpoints;
public Screens screens;
public GlobalStrings globalStrings;


public class Screens
public RegisterStay registerStay;
public CalendarScreen calendar;
public RegisterError registerError;
public BookingNumber bookingNumber;
public InDestDashboard inDestDashboard;
public PreDestDashboard preDestDashboard;
public LocalExcursions localExcursions;
public PreDestMenu preDestMenu;
public InDestMenu inDestMenu;
public EmailSubscribe emailSubscribe;
public UnregisteredLanding unregisteredLanding;



Error message



Caused by java.lang.NullPointerException: Attempt to read from field 'com.royalton.mobileapp.common.repositories.models.appSettings.screens.Screens com.royalton.mobileapp.common.repositories.models.appSettings.AppSettings.screens' on a null object reference
at com.royalton.mobileapp.base.AppModule.providesEmailSubscribeScreen(AppModule.java:192)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:19)
at com.royalton.mobileapp.base.AppModule_ProvidesEmailSubscribeScreenFactory.get(AppModule_ProvidesEmailSubscribeScreenFactory.java:8)






android firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 16:59









Doug Stevenson

79.6k995113




79.6k995113










asked Mar 6 at 13:40









Nagendra KumarNagendra Kumar

63




63












  • At which line of code are you getting NPE and please also add your database structure.

    – Alex Mamo
    Mar 6 at 14:59











  • @AlexMamo Im getting NPE when trying to access the screens variable.

    – Nagendra Kumar
    Mar 6 at 15:23











  • At this line Log.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.

    – Alex Mamo
    Mar 6 at 15:24

















  • At which line of code are you getting NPE and please also add your database structure.

    – Alex Mamo
    Mar 6 at 14:59











  • @AlexMamo Im getting NPE when trying to access the screens variable.

    – Nagendra Kumar
    Mar 6 at 15:23











  • At this line Log.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.

    – Alex Mamo
    Mar 6 at 15:24
















At which line of code are you getting NPE and please also add your database structure.

– Alex Mamo
Mar 6 at 14:59





At which line of code are you getting NPE and please also add your database structure.

– Alex Mamo
Mar 6 at 14:59













@AlexMamo Im getting NPE when trying to access the screens variable.

– Nagendra Kumar
Mar 6 at 15:23





@AlexMamo Im getting NPE when trying to access the screens variable.

– Nagendra Kumar
Mar 6 at 15:23













At this line Log.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.

– Alex Mamo
Mar 6 at 15:24





At this line Log.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.

– Alex Mamo
Mar 6 at 15:24












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024493%2faddvalueeventlistener-for-firebase-read-data-returning-null-on-android-6-0%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024493%2faddvalueeventlistener-for-firebase-read-data-returning-null-on-android-6-0%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко