עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Having issue retrieving data from firebase databse ]

Featured Replies

פורסם

I'm having issue retrieving data from firebase.im trying to get the information related to this node "0506326662" and the sub-node "Location". I also created class named

UserInformation that will hold the data as an object but for some reason i'm getting an error and i have no clue where it comes from and why.

 databaseReference.child("Users").child(numbeT).
                child("Location").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for(DataSnapshot ds:dataSnapshot.getChildren())
                {
                     uInfo=new UserInformation();
                     uInfo.setLastOnline(ds.child(numbeT).getValue(UserInformation.class).getLastOnline());
                    uInfo.setLag(ds.child(numbeT).getValue(UserInformation.class).getLag());
                    uInfo.setLat(ds.child(numbeT).getValue(UserInformation.class).getLat());
2019-03-23 17:58:52.187 4657-4657/com.alrubaye.mytracker E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.alrubaye.mytracker, PID: 4657
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.text.SimpleDateFormat com.alrubaye.mytracker.UserInformation.getLastOnline()' on a null object reference
        at com.alrubaye.mytracker.MyServie$1.onDataChange(MyServie.java:79)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.1.0:75)
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.1.0:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.1.0:55)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
package com.alrubaye.mytracker;

import java.text.SimpleDateFormat;

public class UserInformation {
    private SimpleDateFormat lastOnline;
    private String lag;
    private String lat;

    public UserInformation() {

    }

    public SimpleDateFormat getLastOnline() {
        return lastOnline;
    }

    public void setLastOnline(SimpleDateFormat lastOnline) {
        this.lastOnline = lastOnline;
    }

    public String getLag() {
        return lag;
    }

    public void setLag(String lag) {
        this.lag = lag;
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat;
    }
}
                }

Capture.JPG

פורסם

משהו בעימוד של הקוד יוצא הפוך באתר ומקשה מאוד לקרוא אותו.

 

מעולם לא עבדתי עם firebase אבל לפי הודעת השגיאה ברורה הבעיה. אתה מנסה לפנות ל-UserInformation של הרשומה ולבצע פעולת getLastOnline אבל לרשומה שאתה פונה אליה אין UserInformation ולכן אתה מקבל NullPointerException, גם בתמונת הנתונים מה-db אפשר לראות שאין שם UserInformation.

 

תשנה את הקוד שלך למשהו כזה, גם מבחינת ביצועים וקריאות קוד זה עדיף:

for(DataSnapshot ds:dataSnapshot.getChildren()) {
   UserInformation dataInfo = ds.child(numbeT).getValue(UserInformation.class)
   if (dataInfo != null){
      uInfo = new UserInformation();
      uInfo.setLastOnline(dataInfo.getLastOnline());
      uInfo.setLag(dataInfo.getLag());
      uInfo.setLat(dataInfo.getLat());
   }

 

 

נערך על-ידי etal

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.