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

Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

What does it take to become a wilderness skills guide as a business?

School performs periodic password audits. Is my password compromised?

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

Generating a list with duplicate entries

Why do we call complex numbers “numbers” but we don’t consider 2-vectors numbers?

Short story about an infectious indestructible metal bar?

Unfamiliar notation in Diabelli's "Duet in D" for piano

Why would /etc/passwd be used every time someone executes `ls -l` command?

Having the player face themselves after the mid-game

How to educate team mate to take screenshots for bugs with out unwanted stuff

Trigger on Custom Object Share

Should I file my taxes? No income, unemployed, but paid 2k in student loan interest

Unidentified signals on FT8 frequencies

What is the oldest European royal house?

How do property taxes on school district bonds work?

Giving a talk in my old university, how prominently should I tell students my salary?

The (Easy) Road to Code

Is there a math expression equivalent to the conditional ternary operator?

Did Amazon pay $0 in taxes last year?

Why restrict private health insurance?

How to make sure I'm assertive enough in contact with subordinates?

Help! My Character is too much for her story!



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
    2 days ago











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

    – Nagendra Kumar
    2 days ago











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

    – Alex Mamo
    2 days ago















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
    2 days ago











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

    – Nagendra Kumar
    2 days ago











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

    – Alex Mamo
    2 days ago













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 2 days ago









Doug Stevenson

79.3k995113




79.3k995113










asked 2 days ago









Nagendra KumarNagendra Kumar

63




63












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

    – Alex Mamo
    2 days ago











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

    – Nagendra Kumar
    2 days ago











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

    – Alex Mamo
    2 days ago

















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

    – Alex Mamo
    2 days ago











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

    – Nagendra Kumar
    2 days ago











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

    – Alex Mamo
    2 days ago
















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

– Alex Mamo
2 days ago





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

– Alex Mamo
2 days ago













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

– Nagendra Kumar
2 days ago





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

– Nagendra Kumar
2 days ago













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

– Alex Mamo
2 days ago





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

– Alex Mamo
2 days ago












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

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229