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
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)
add a comment |
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)
At which line of code are you gettingNPEand 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 lineLog.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.
– Alex Mamo
2 days ago
add a comment |
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)
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)
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 gettingNPEand 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 lineLog.e("NAG",appSettingsData.screens.toString());? Please add the entire error to your question.
– Alex Mamo
2 days ago
add a comment |
At which line of code are you gettingNPEand 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 lineLog.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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
At which line of code are you getting
NPEand 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