in main activity, work working , there no problem firebase. in other activities, firebase sends data setvalue
application crashes after that.why?
public class main_activity extends appcompatactivity { static string firstoption; static string optionfour; static string secondoption; static string thirdoption; static string thequestion; static string correctanswer; public static string[] str = new string[100]; private int index_yoni=0; private textview mainpagetitle; private firebaseauth firebaseauth; private firebase fire; private string uid; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main_activity); firebase.setandroidcontext(main_activity.this); fire = new firebase("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"); mainpagetitle=(textview) findviewbyid(r.id.textview3); fire.addvalueeventlistener(new valueeventlistener() { public void ondatachange(datasnapshot datasnapshot) { firebaseauth=firebaseauth.getinstance(); firebaseuser user=firebaseauth.getcurrentuser(); if (firebaseauth.getcurrentuser() != null) { mainpagetitle.settext(datasnapshot.child("userinformation").child(user.getuid()).child("name").getvalue()+" "+"'welcome"); } else { mainpagetitle.settext("'welcom game"); } } public void oncancelled(firebaseerror firebaseerror) { log.e("the error ....", firebaseerror.getmessage()); } }); fire.addvalueeventlistener(new valueeventlistener() { public void ondatachange(datasnapshot datasnapshot) { (datasnapshot sportsnapshot : datasnapshot.child(typesoftests.topic).getchildren()) { sportsquestions sportsquestions = sportsnapshot.getvalue(sportsquestions.class); firstoption = sportsquestions.getfirstoption(); optionfour = sportsquestions.getoptionfour(); secondoption = sportsquestions.getsecondoption(); thirdoption = sportsquestions.getthirdoption(); correctanswer = sportsquestions.getcorrectanswer(); thequestion = sportsquestions.getthequestion(); increment(); } } public void oncancelled(firebaseerror firebaseerror) { log.e("the error ....", firebaseerror.getmessage()); } } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_profile2); firebase.setandroidcontext(profileactivity.this); fire= new firebase("https://triviaproject-4c91e.firebaseio.com/"); fire.child("userinformation").child(user.getuid()).setvalue(userinformation);
fire.addvalueeventlistener(new valueeventlistener() { public void ondatachange(datasnapshot datasnapshot) { (datasnapshot sportsnapshot : datasnapshot.child(typesoftests.topic).getchildren()) { sportsquestions sportsquestions = sportsnapshot.getvalue(sportsquestions.class); firstoption = sportsquestions.getfirstoption(); optionfour = sportsquestions.getoptionfour(); secondoption = sportsquestions.getsecondoption(); thirdoption = sportsquestions.getthirdoption(); correctanswer = sportsquestions.getcorrectanswer(); thequestion = sportsquestions.getthequestion(); increment(); } //you need add add stop fire.removeeventlistener(this) }
Comments
Post a Comment