com.google.firebase.database.DatabaseException:在android.view.animation.AccelerateDecelerateInterpolator类上找不到要序列化的属性

问题描述 投票:0回答:1

我正在尝试构建小型多人骰子游戏。为此,当我单击带有随机生成的骰子结果的按钮时,我想更新连接的实时数据库。除了结果,我还制作了三个骰子的动画。

在动画开始前单击按钮时,更新我的数据库的功能很好用。动画开始后单击按钮时,总是出现以下错误:

com.google.firebase.database.DatabaseException: No properties to serialize found on class android.view.animation.AccelerateDecelerateInterpolator at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-database@@19.2.1:547) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-database@@19.2.1:329) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.2.1:166) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.2.1:47) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.2.1:675) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.2.1:167) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.2.1:47) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.2.1:675) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.2.1:167) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$200(com.google.firebase:firebase-database@@19.2.1:47) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.serialize(com.google.firebase:firebase-database@@19.2.1:675) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.2.1:167) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:firebase-database@@19.2.1:60) at com.google.firebase.database.DatabaseReference.setValueInternal(com.google.firebase:firebase-database@@19.2.1:282) at com.google.firebase.database.DatabaseReference.setValue(com.google.firebase:firebase-database@@19.2.1:159) at com.example.trdfschockt.MainActivity$1.onClick(MainActivity.java:81) at android.view.View.performClick(View.java:6597) at android.view.View.performClickInternal(View.java:6574) at android.view.View.access$3100(View.java:778) at android.view.View$PerformClick.run(View.java:25885) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我尝试将每个属性设置为公共,在每个类中实现了可序列化,甚至检查了proguard-rules文件。

这里是出现问题的代码段:

``公共类MainActivity扩展AppCompatActivity实现Serializable {

public static final Random RANDOM = new Random();
public Button rollDices, stopRoll, startAgain;
public Integer value, diceRollCounter, firstDice, secondDice, thirdDice;
public ImageView imageView1, imageView2, imageView3;
public TextView textView1;
public static int[] diceResults = new int[3];
public static schockDecision newDecision;
public static Dice[] dices = new Dice[3];
public Player player = new Player();
public DatabaseReference myRef;
public Animation anim1, anim2, anim3;

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

    rollDices = (Button) findViewById(R.id.rollDices);
    stopRoll = (Button) findViewById(R.id.stopRoll);
    startAgain = (Button) findViewById(R.id.startAgain);
    imageView1 = (ImageView) findViewById(R.id.imageView1);
    imageView2 = (ImageView) findViewById(R.id.imageView2);
    imageView3 = (ImageView) findViewById(R.id.imageView3);

    for (int i = 0; i < dices.length; i++) {
        dices[i] = new Dice();
        dices[i].setShouldDiceBeRolled(true);
        dices[i].setNumber(0);
    }

    diceRollCounter = 0;

    startAgain.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            rollDices.setEnabled(true);
            myRef = FirebaseDatabase.getInstance().getReference("Player");
            String id = myRef.push().getKey();
            player.setUserId("asc");
            player.setSchockResult(0);
            player.setAmountDeckel(0);
            player.setUserName("Hans22112");
            player.setAufdeckReihenfolge(0);
            player.setFirstDice(dices[0]);
            player.setSecondDice(dices[1]);
            player.setThirdDice(dices[2]);
            myRef.child(id).setValue(player);
        }

     }
    );

    stopRoll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            endOfRound();
        }
     }
    );

    rollDices.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            diceRollCounter += 1;

            anim1 = AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake);
            anim2 = AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake);
            anim3 = AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake);
            final Animation.AnimationListener animationListener = new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    value = randomDiceValue();
                    int res = getResources().getIdentifier("dice_" + value, "drawable", "com.example.trdfschockt");
                    //if (animation == anim1) {
                    if (animation == anim1) {
                        imageView1.setImageResource(res);
                        diceResults[0] = value;
                        dices[0].setNumber(value);
                    } else if (animation == anim2) {
                        imageView2.setImageResource(res);
                        diceResults[1] = value;
                        dices[1].setNumber(value);
                    } else if (animation == anim3) {
                        imageView3.setImageResource(res);
                        diceResults[2] = value;
                        dices[2].setNumber(value);
                    }
android firebase firebase-realtime-database android-animation
1个回答
0
投票

[大多数Android类,例如android.view.animation.AccelerateDecelerateInterpolator,除非您为此编写自定义代码,否则无法将其写入数据库。

您的代码将需要从AccelerateDecelerateInterpolator中提取重要值并写入Firebase。然后,当您从数据库中读取时,您将不得不再次从这些属性中创建一个AccelerateDecelerateInterpolator

另请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.