0

Got these errors in Run logcat: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.shikh.regie, PID: 19366 com.google.firebase.database.DatabaseException: Failed to parse node with class class com.example.shikh.regie.User at com.google.android.gms.internal.zzamm.zza(Unknown Source) at com.google.android.gms.internal.zzamm.zzbt(Unknown Source) at com.google.android.gms.internal.zzamp.zzbu(Unknown Source) at com.google.firebase.database.DatabaseReference.setValue(Unknown Source) at com.example.shikh.regie.MainActivity$1.onClick(MainActivity.java:40)

Dont know whats the problem.why it is not able to parse the node

MainActivity.java

public class MainActivity extends AppCompatActivity {
private EditText name,email,phone;
private Button btn;
private DatabaseReference mDatabse;
private String name1,email1,phone1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDatabse = FirebaseDatabase.getInstance().getReference().child("AppUsers");

    name = (EditText) findViewById(R.id.editText);
    email = (EditText) findViewById(R.id.editText2);
    phone = (EditText) findViewById(R.id.editText3);

    name1 = name.getText().toString();
    email1 = email.getText().toString();
    phone1 = phone.getText().toString();
    btn = (Button) findViewById(R.id.button);
         btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Map<String, User> users = new HashMap<String, User>();
            DatabaseReference ref=mDatabse.child("AppUsers");
            mDatabse.setValue(email1,new User(name1,email1,phone1));
            mDatabse.setValue(users);
        }
    });

}
}

User.java

package com.example.shikh.regie;


public class User {
String name,email,phone;

public User(){}

public User(String name, String email, String phone) {
    this.name = name;
    this.email = email;
    this.phone = phone;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}
 }
3

1 Answer 1

1

This code will not work:

mDatabse.setValue(email1,new User(name1,email1,phone1));

The only [matching overload of setValue()](https://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReference.html#setValue(java.lang.Object, java.lang.Object)) is:

public Task<Void> setValue (Object value, Object priority)

Set the data and priority to the given values.

In this overload the second argument is a priority value, which has to be a primitive object.

It seems more likely that you're looking to do:

mDatabse.child("email1").setValue(new User(name1,email1,phone1));

This will set the new user as node email1 under the reference.

Sign up to request clarification or add additional context in comments.

6 Comments

i want the parent node should b named as the user's email...each user will have his own record under his parent node a his email
For that you'd specify the email address instead of email1 in the above snippet. Just be sure to encode the email, since . is not allowed in Firebase keys. The common way is to replace the . by a ,.
Note: email addresses can contain many characters which are not allowed in a firebase key. Also using email as key does not allow users to change their email address. To solve both I store users using a UUID. On start of my application, I just load all users in memory in a hash map by email address.
@bluevoid The set of disallowed characters in Firebase keys is quite small and most of those cannot occur on an email address. The dot . is really the only one we encode as far as I know. Loading all users into memory may work when you app starts, but becomes a scalability bottleneck if/when you have thousands/millions of users.
Ok, it is not really bigset: not allowed in firebase fieldname: .$[]#/ Allowed in email: !#$%&'*+-/=?^_`{|}~; and [] are allowed when between quotes. So to get complete coverage you need to replace all of them. See discusion here: grokbase.com/t/gg/firebase-talk/154q27rryc/…. Their solution is to urlencode the email AND replace the dot. Loading all users will become a bottleneck when more than a few thousand, that is true.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.