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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page