com.google.firebase.database.DatabaseException: не найдено свойств для сериализации в классе android .view.animation.AccelerateDecelerateInterpolator - PullRequest
0 голосов
/ 07 апреля 2020

Я пытаюсь создать небольшую многопользовательскую игру в кости. Для этого я хочу обновить мою подключенную базу данных в реальном времени, нажимая на кнопку со случайно сгенерированными результатами игры в кости. В дополнение к результатам я сделал анимацию для моих трех кубиков.

При нажатии кнопки до запуска анимации функция обновления моей базы данных работает хорошо. Когда я нажимаю кнопку после запуска анимации, я всегда получаю следующую ошибку:

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)

Я пытался установить для каждого атрибута значение publi c, реализовал Serializable в каждом классе и даже проверил файл правил proguard.

Вот фрагмент кода, в котором возникает проблема:

`` publi c класс 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);
                    }

1 Ответ

0 голосов
/ 07 апреля 2020

Большинство Android классов, таких как android.view.animation.AccelerateDecelerateInterpolator, не могут быть записаны в базу данных, если вы не написали специальный код для этого.

Ваш код должен будет извлечь важные значения из AccelerateDecelerateInterpolator и написать в Firebase. Затем, когда вы будете читать из базы данных, вам придется снова создать AccelerateDecelerateInterpolator из этих свойств.

Также см .:

...