4

I created sign in app and I am using with firebase database. But I have a problem when I am trying to save object in the database. Although when I am trying to save simple string or simple HashMap object everything working.

I got an error:

com.google.firebase.database.DatabaseException: Found a conflicting setters with name: setWallpaper (conflicts with setWallpaper defined on android.content.ContextWrapper)

Here is my code:

Main Activity:

public class MainActivity extends AppCompatActivity {
    EditText userName;
    EditText password;
    Button signInbtn;
    DatabaseReference url;
    Map<String, User> users = new HashMap<String, User>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final FirebaseDatabase database = FirebaseDatabase.getInstance();
        url = database.getInstance().getReference();
        userName = (EditText) findViewById(R.id.userName);
        password = (EditText) findViewById(R.id.password);
        signInbtn = (Button) findViewById(R.id.signInBtn);
        signInbtn.setOnClickListener(signObject);

    }  
    View.OnClickListener signObject = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            User user = new User("Moshe","1234");
            users.put("101",user);
            DatabaseReference userUrl = url.child("Users");
            userUrl.setValue(users);
            System.out.println(users);
        }
    };

Class User:

public class User extends Application{

    public static String password;
    public static String name ;

    public User(){

    }

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

    public  String getName() {
        return name;
    }

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

    public  String getPassword() {
        return password;
    }

    public  void setPassword(String password) {
        User.password = password;
    }
}

I added permmision.Internet to the manifest. I read a lot of question about this subject and specially about Firebase, but I did not find any solution to my problem.

1 Answer 1

4

Firebase can only read and write fairly basic Java objects (so-called Plain Old Java Objects or POJOs) to the database. By extending your User class from Application, you're violating those rules.

The solution is to make your User class completely standalone:

public class User {
    ...
Sign up to request clarification or add additional context in comments.

2 Comments

i did what you say now the app not crushing while it is compiling but still it is not saving the data
That could be for many reasons and really would be a different question. That said: I'd start by listening for security problems in setValue(). See stackoverflow.com/documentation/firebase/5548/…

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.