发现名称的冲突吸气剂:getText [英] found conflicting getters for name: getText

查看:52
本文介绍了发现名称的冲突吸气剂:getText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将书籍保存到数据库时发生以下异常:

following exception occurs when trying to save the book into a database:

我的代码(从此处删除了默认导入):

My Code (removed default imports from here):

public class AddBookActivity extends AppCompatActivity {

所有变量都在这里初始化..

All variables are initialized here..

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_book);

    mAuth = FirebaseAuth.getInstance();
    currentUserID = mAuth.getCurrentUser().getUid();
    current_user_id = mAuth.getUid();
    BookReference = FirebaseStorage.getInstance().getReference();
    userRef = FirebaseDatabase.getInstance().getReference();
    bookRef = FirebaseDatabase.getInstance().getReference().child("Books");

    selectBookImage = (ImageButton) findViewById(R.id.addimageButton);
    addBookButton = (Button) findViewById(R.id.buttonAddBook);
    bookTitle = (EditText) findViewById(R.id.addbookTitle);
    bookDescription = (EditText) findViewById(R.id.addbookDescription);
    bookAuthor = (EditText) findViewById(R.id.addbookAuthor);

    loadingBar = new ProgressDialog(this);

    mToolBar = (Toolbar) findViewById(R.id.add_book_toolbar);
    setSupportActionBar(mToolBar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle("წიგნის დამატება");

    selectBookImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            OpenGallery();
        }
    });

    addBookButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ValidateBookInfo();
        }
    });
}

private void ValidateBookInfo() {
    Author = bookAuthor.getText().toString();
    Description = bookDescription.getText().toString();
    Title = bookTitle.getText().toString();
    if (ImageUrl == null){
        Toast.makeText(this,"წიგნის სურათი არ შეიძლება იყოს ცარიელი",Toast.LENGTH_SHORT).show();
    }
    if (TextUtils.isEmpty(Author)){
        Toast.makeText(this,"წიგნის სათაური არ შეიძლება იყოს ცარიელი",Toast.LENGTH_SHORT).show();
    }
    if (TextUtils.isEmpty(Description)){
        Toast.makeText(this,"წიგნის აღწერა არ შეიძლება იყოს ცარიელი",Toast.LENGTH_SHORT).show();
    }
    if (TextUtils.isEmpty(Title)){
        Toast.makeText(this,"წიგნის ავტორი არ შეიძლება იყოს ცარიელი",Toast.LENGTH_SHORT).show();
    }
    else{
        loadingBar.setTitle("ახალი წიგნის დამატება");
        loadingBar.setMessage("გთხოვთ დაელოდეთ.. წიგნი იტვირთება..");
        loadingBar.show();
        loadingBar.setCanceledOnTouchOutside(true);
        StoringImageToStorage();
    }
}

private void StoringImageToStorage() {
    Calendar callForDate = Calendar.getInstance();
    SimpleDateFormat currentDate = new SimpleDateFormat("dd-MMMM-yyyy");
    saveCurrentDate = currentDate.format(callForDate.getTime());

    Calendar callForTime = Calendar.getInstance();
    SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm");
    saveCurrentTime = currentTime.format(callForTime.getTime());

    bookRandomName = saveCurrentDate + saveCurrentTime;

    StorageReference filePath = BookReference.child("Book Images").child(ImageUrl.getLastPathSegment() + bookRandomName + ".jpg");

    filePath.putFile(ImageUrl).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
            if (task.isSuccessful()){
                DownloadURL = task.getResult().toString();
                Toast.makeText(AddBookActivity.this,"წიგნის სურათი წარმატებით აიტვირთა",Toast.LENGTH_SHORT).show();

                SaveBookToDatabase();
            }else{
                String message = task.getException().getMessage();
                Toast.makeText(AddBookActivity.this,"დაფიქსირდა შეცდომა " + message,Toast.LENGTH_SHORT).show();
            }
        }
    });

}

private void SaveBookToDatabase() {
    userRef.child(current_user_id).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if(dataSnapshot.exists()){
                Integer BookLikes = 0;

                HashMap booksMap = new HashMap();
                booksMap.put("uid",current_user_id);
                booksMap.put("date",saveCurrentDate);
                booksMap.put("time",saveCurrentTime);
                booksMap.put("title",bookTitle);
                booksMap.put("description",bookDescription);
                booksMap.put("author",bookAuthor);
                booksMap.put("booksimage",DownloadURL);
                booksMap.put("likes",BookLikes);

                bookRef.child(current_user_id + bookRandomName).updateChildren(booksMap)
                        .addOnCompleteListener(new OnCompleteListener() {
                            @Override
                            public void onComplete(@NonNull Task task) {
                                if (task.isSuccessful()){
                                    SendUserToHomePageActivity();
                                    Toast.makeText(AddBookActivity.this,"წიგნი წარმატებით დაემატა!",Toast.LENGTH_SHORT).show();
                                    loadingBar.dismiss();
                                }else {
                                    String message = task.getException().getMessage();
                                    Toast.makeText(AddBookActivity.this,"დაფიქსირდა შეცდომა" + message,Toast.LENGTH_SHORT).show();
                                    loadingBar.dismiss();
                                }
                            }
                        });


            }
        }

    });
}



@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode==Gallery_Pick && resultCode==RESULT_OK && data!=null){
        ImageUrl = data.getData();
        selectBookImage.setImageURI(ImageUrl);

    }
}

}

这是我在运行应用程序并将书添加到数据库时获取的错误,请注意,图像已成功上传,然后导致应用程序崩溃:

This is the Error Im getting when im running the app and adding book to database, Please note that Image is uploading successfully and then comes the app crash:

2018-11-11 02:03:13.068 29281-29281/com.example.t3hjeff.bookshelf E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.t3hjeff.bookshelf, PID: 29281
    com.google.firebase.database.DatabaseException: Found conflicting getters for name: getText

推荐答案

注意以下行:

bookTitle = (EditText) findViewById(R.id.addbookTitle);//bookTitle is an EditText object
...
booksMap.put("title",bookTitle);//it can not be serialized/deserialized

Firebase数据库只能存储JSON类型,因此您不能将EditText传递给它.

The Firebase Database can only store JSON types, so you cannot pass a EditText to it.

 Title = bookTitle.getText().toString();
 ...
 booksMap.put("title",Title );//modify like this.

这篇关于发现名称的冲突吸气剂:getText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆