Ziel: (. In Android) Ich versuche, Daten von Firebase zu ziehen und die Werte in Strings aus verschachtelten Knoten einfügenFirebase - (DataSnapshot mit mehreren untergeordneten Knoten) - Nullpointer
Hinweis: Es ist FINE für das erste Variable/Schlüssel-Wert-Paar (mnum), sondern bekommt Nullpointer für die anderen
Forschung: Firebase docs, Youtube, über diese spe Stackoverflow cific Frage wie: How to get child of child value from firebase in android?
Wie das andere gilt: Mühe der Suche nach Informationen auf immer Firebase Datenbank-Informationen, wenn DB mehrere Verschachtelungen hat
Fehler:
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.i(Log.java:211)
at com.netgalaxystudios.timeclock.RegisterSubscriptionActivity$1.onDataChange(RegisterSubscriptionActivity.java:80)
Die Fehlerpunkte diese Zeile: Log.i ("Mikroname", Mikro);
Datenbank: Bild von Firebase-DB, der
RegisterSubscriptionActivity.java verwendet wird:
public class RegisterSubscriptionActivity extends Activity {
private DatabaseReference mDatabase;
private DatabaseReference mDatabaseMicro;
ArrayList subscriptionInfo;
//Subscription (String) values
String micro, small, medium, large, enterprise;
String mNum, sNum, medNum, lNum, eNum;
String mPrice, sPrice, medPrice, lPrice, ePrice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_subscription);
subscriptionInfo = new ArrayList<>();
//GET INSTANCE OF FIREBASE DB & GRAB SUBSCRIPTION DATA
mDatabase = FirebaseDatabase.getInstance().getReference("Subscription");
mDatabaseMicro = mDatabase.child("Micro");
mDatabaseMicro.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) { //literally a "snapshot" of the data
//dataSnapshot.
for(DataSnapshot subscriptionDataSnapshot : dataSnapshot.getChildren()) {
if (subscriptionDataSnapshot.getKey().equals("mNum")) {
mNum= subscriptionDataSnapshot.getValue().toString();
}
if(subscriptionDataSnapshot.getKey().equals("mPrice")) {
mPrice = subscriptionDataSnapshot.getValue().toString();
}
if(subscriptionDataSnapshot.getKey().equals("micro")) {
micro = subscriptionDataSnapshot.getValue().toString();
}
Log.i("micro number", mNum);
//Log.i("micro price", mPrice);
Log.i("micro name", micro);
String subscriptions = subscriptionDataSnapshot.getValue(String.class); //Each time it gets the key/value pair per node
subscriptionInfo.add(subscriptions);
}