Java com.google.firebase.database.DatabaseException:类未定义无参数构造函数
在Android开发方面,我是一个新手。我的项目一直有一个问题,我似乎无法解决 我最近开发了一个食品和食谱应用程序,其想法是能够将食谱上传到FireBase,当我运行该应用程序时,我必须从图库中选择一个图像,并键入名称描述和价格,问题是,在我上传第一个配方后,只有图像被上传到我的FireBase,并且应用程序在我上传配方后立即崩溃,现在每次我运行应用程序时,它都会立即停止,并显示一个致命的异常,我制作了这个应用程序,从这个频道观看Youtube视频。我在第4部分视频中对我的问题发表了评论,因为他花了很长时间回复我。我在这里寻求帮助,我不知道出了什么问题,我希望有人能帮我解决这个问题 以下是错误:Java com.google.firebase.database.DatabaseException:类未定义无参数构造函数,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,在Android开发方面,我是一个新手。我的项目一直有一个问题,我似乎无法解决 我最近开发了一个食品和食谱应用程序,其想法是能够将食谱上传到FireBase,当我运行该应用程序时,我必须从图库中选择一个图像,并键入名称描述和价格,问题是,在我上传第一个配方后,只有图像被上传到我的FireBase,并且应用程序在我上传配方后立即崩溃,现在每次我运行应用程序时,它都会立即停止,并显示一个致命的异常,我制作了这个应用程序,从这个频道观看Youtube视频。我在第4部分视频中对我的问题发表了评论,因为他
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.recipeapp, PID: 14845
com.google.firebase.database.DatabaseException: Class com.example.recipeapp.FoodData does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.4:557)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.4:550)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.4:420)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.4:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.0.4:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.0.4:212)
at com.example.recipeapp.MainActivity$1.onDataChange(MainActivity.java:69)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.0.4:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.0.4:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.0.4:55)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
这是我的主要活动代码:
package com.example.recipeapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
List<FoodData> myFoodList;
FoodData mFoodData;
ProgressDialog progressDialog;
MyAdapter myAdapter;
EditText txt_search;
private DatabaseReference databaseReference;
private ValueEventListener eventListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = findViewById(R.id.RecyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 1);
mRecyclerView.setLayoutManager(gridLayoutManager);
txt_search = (EditText) findViewById(R.id.txt_searchtext);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Carregando Itens...");
myFoodList = new ArrayList<>();
final MyAdapter myAdapter = new MyAdapter(MainActivity.this, myFoodList);
mRecyclerView.setAdapter(myAdapter);
databaseReference = FirebaseDatabase.getInstance().getReference("Recipe");
progressDialog.show();
eventListener = databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
myFoodList.clear();
for (DataSnapshot itemSnapshot : dataSnapshot.getChildren()) {
FoodData foodData = itemSnapshot.getValue(FoodData.class);
myFoodList.add(foodData);
}
myAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
progressDialog.dismiss();
}
});
txt_search.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
filter(s.toString());
}
});
}
private void filter(String text) {
ArrayList<FoodData> filterList = new ArrayList<>();
for (FoodData item : myFoodList) {
if (item.getItemName().toLowerCase().contains(text.toLowerCase())) ;
{
filterList.add(item);
}
}
myAdapter.filteredList(filterList);
}
public void btn_uploadActivity(View view) {
startActivity(new Intent(this, Upload_Recipe.class));
}
}
我建议你在网上搜索你不理解的错误信息。经常有人会遇到同样的错误。谢谢你,这是我第一次看到这个错误,有时我在搜索时会遇到困难,但我会看看我能找到什么。我已经做了搜索,并在Stack Oveflow上标记了我找到的重复项。在未来,节省时间并在询问之前先搜索是很好的。很抱歉,我以前做过研究,但没有人匹配我的代码,这会让事情变得更困难,我没有任何经验,我只在家通过youtube练习。没有人解决我的问题,错误甚至不匹配,我甚至不知道出了什么问题。我建议你在网上搜索你不理解的错误信息。经常有人会遇到同样的错误。谢谢你,这是我第一次看到这个错误,有时我在搜索时会遇到困难,但我会看看我能找到什么。我已经做了搜索,并在Stack Oveflow上标记了我找到的重复项。在未来,节省您的时间并在询问之前先搜索是很好的。对不起,我以前做过研究,但没有人匹配我的代码,这会让事情变得更困难,我没有任何经验,我只在家通过youtube练习。这些都没有解决我的问题,错误甚至不匹配,我甚至不知道出了什么问题。
package com.example.recipeapp;
public class FoodData {
private String itemName;
private String itemDescription;
private String itemPrice;
private String itemImage;
public FoodData(String itemName, String itemDescription, String itemPrice, String itemImage) {
this.itemName = itemName;
this.itemDescription = itemDescription;
this.itemPrice = itemPrice;
this.itemImage = itemImage;
}
public String getItemName() {
return itemName;
}
public String getItemDescription() {
return itemDescription;
}
public String getItemPrice() {
return itemPrice;
}
public String getItemImage() {
return itemImage;
}
}