Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

database - android save object in firebase

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...