Błąd "declares multiple JSON fields named mLifecycleRegistry"

0

Witam jest ktoś w stanie powiedzieć czemu to nie działa?

package com.example.pam3;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {
    EditText firstname, lastname, street, dnumber, mnumber, city, pcode;
    TextView birthdate;
    RadioButton male, female;
    CheckBox swimming, basketball, horseriding, jogging, soccer, volleyball;
    Button send, clear;
    ArrayList<RadioButton> sex;
    ArrayList<CheckBox> activities;
    DatePickerDialog picker;
    private int year, month, day;

    private void clear_all(){
        for (CheckBox c:activities)
            c.setChecked(false);
        firstname.setText("");
        lastname.setText("");
        birthdate.setText("");
        street.setText("");
        dnumber.setText("");
        mnumber.setText("");
        city.setText("");
        pcode.setText("");
        female.setText("");
        male.setText("");
    }
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Locale locale = new Locale("PL");
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getApplicationContext().getResources().updateConfiguration(config, null);
        setContentView(R.layout.activity_main);
        firstname = (EditText) findViewById(R.id.imie);
        lastname = (EditText) findViewById(R.id.nazwisko);
        birthdate = (EditText) findViewById(R.id.dataurodzenia);
        street = (EditText) findViewById(R.id.ulica);
        dnumber = (EditText) findViewById(R.id.numerd);
        mnumber = (EditText) findViewById(R.id.numerm);
        city = (EditText) findViewById(R.id.miasto);
        pcode = (EditText) findViewById(R.id.kod);
        male = (RadioButton) findViewById(R.id.mezczyzna);
        female = (RadioButton) findViewById(R.id.kobieta);
        swimming = (CheckBox) findViewById(R.id.plywanie);
        basketball = (CheckBox) findViewById(R.id.koszykowka);
        horseriding = (CheckBox) findViewById(R.id.jazdakonna);
        jogging = (CheckBox) findViewById(R.id.bieganie);
        soccer = (CheckBox) findViewById(R.id.pilkanozna);
        volleyball = (CheckBox) findViewById(R.id.siatkowka);
        send = (Button) findViewById(R.id.wyslij);
        clear = (Button) findViewById(R.id.wyczysc);

        sex = new ArrayList<RadioButton>();
        sex.add(male);
        sex.add(female);
        activities = new ArrayList<CheckBox>();
        activities.add(swimming);
        activities.add(jogging);
        activities.add(horseriding);
        activities.add(basketball);
        activities.add(volleyball);
        activities.add(soccer);

        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clear_all();
                }
            });
            birthdate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final Calendar cldr = Calendar.getInstance();
                    int day = cldr.get(Calendar.DAY_OF_MONTH);
                    int month = cldr.get(Calendar.MONTH);
                    int year = cldr.get(Calendar.YEAR);
                    picker = new DatePickerDialog(MainActivity.this,
                            new DatePickerDialog.OnDateSetListener() {
                                @Override
                                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                                    birthdate.setText(dayOfMonth + "." + (monthOfYear + 1) + "." + year);
                                }
                            }, year, month, day);
                    picker.show();
                }
            });

            send.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Person person = new Person(
                            firstname.getText().toString(),
                            lastname.getText().toString(),
                            male.isChecked(),
                            city.getText().toString(),
                            street.getText().toString(),
                            dnumber.getText().toString(),
                            mnumber.getText().toString(),
                            pcode.getText().toString(),
                            birthdate.getText().toString()
                            );
                    for (CheckBox c : activities) {
                        if (c.isChecked()) {
                            person.AddActivity(c.getText().toString());
                        }
                    }
                    StartSummary(person);
                }
            });
        }
        public void StartSummary(Person p){
            Intent intent = new Intent(MainActivity.this,SummaryActivity.class);
            Gson gson = new Gson();
            intent.putExtra("person", gson.toJson(p));
            this.startActivity(intent);
        }
package com.example.pam3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

import com.google.gson.Gson;

public class SummaryActivity extends AppCompatActivity {
    TextView summary;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_summary);
        summary = (TextView)findViewById(R.id.summary);
        Gson gson = new Gson();
        String strobj = getIntent().getStringExtra("person");
        Person person = gson.fromJson(strobj, Person.class);
        summary.setText(person.toString());
    }
}
package com.example.pam3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class Person extends AppCompatActivity {
    public Person(String toString, String toString1, boolean checked, String toString2, String toString3, String toString4, String toString5, String toString6, String toString7) {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void AddActivity(String toString) {
    }
}

Błąd

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pam3, PID: 8821
    java.lang.IllegalArgumentException: class com.example.pam3.Person declares multiple JSON fields named mLifecycleRegistry
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
        at com.google.gson.Gson.getAdapter(Gson.java:458)
        at com.google.gson.Gson.toJson(Gson.java:696)
        at com.google.gson.Gson.toJson(Gson.java:683)
        at com.google.gson.Gson.toJson(Gson.java:638)
        at com.google.gson.Gson.toJson(Gson.java:618)
        at com.example.pam3.MainActivity.StartSummary(MainActivity.java:139)
        at com.example.pam3.MainActivity$3.onClick(MainActivity.java:132)
        at android.view.View.performClick(View.java:7448)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28305)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
1

JSON, ktory probujesz zdeserializowac jest nieprawidlowy - zawiera kilka pól o tej samej nazwie.

1 użytkowników online, w tym zalogowanych: 0, gości: 1