как исправить исключение java .langIllegal для фрагментов? - PullRequest
0 голосов
/ 26 февраля 2020

Я создал приложение с контрольным списком, и когда пользователь добавляет чек к приложению, я получаю сообщение об ошибке ниже и крад sh. Может кто-нибудь дать совет, как это исправить? Поскольку я использую фрагменты, я создал второй Java файл и сослался на него в XML, поскольку вы не можете иметь более одного класса в одном Java, я попытался объединить их, но получил много ошибки и не может использовать publi c класс «расширяет» более одного раза.

Вот ошибка Java error when pressing add Вот XML

<TextView
    android:id="@+id/text_checklist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:textAlignment="center"
    android:textSize="20sp"
    android:visibility="invisible"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Checklist"
    android:textAlignment="center"
    android:textAllCaps="false"
    android:textSize="24sp"
    android:textStyle="bold"
    android:typeface="normal"
    app:fontFamily="@font/basic"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.491"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/text_checklist"
    app:layout_constraintVertical_bias="0.0" />

<EditText
    android:id="@+id/inputText"
    android:layout_width="369dp"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="13dp"
    android:ems="10"
    android:hint="@string/placeholder"
    android:inputType="textPersonName" />

<Button
    android:id="@+id/check_list_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="57dp"
    android:onClick="addButton2"
    android:text="@string/buttonText" />

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="0dp"
    android:layout_marginLeft="0dp"
    android:layout_marginTop="107dp" />

Heres 1-й Java (фрагмент)

    checklistViewModel =
            ViewModelProviders.of(this).get(com.example.csd301_project_trackday_timing_dh.ui.checklist.ChecklistViewModel.class);
    View root = inflater.inflate(R.layout.fragment_checklist, container, false);
    final TextView textView = root.findViewById(R.id.text_checklist);

    checklistViewModel.getText().observe(this, new Observer<String>() {
        @Override
        public void onChanged(@Nullable String s) {
            textView.setText(s);
        }
    });


    return root;
}

}

Heres 2-й Java (CheckList)

Button btn_checklist;
EditText inputText;
ListView listView;
ArrayList<String> list;



public void addButton2(View view){

    String text = inputText.getText().toString();
    list.add(text);
    ArrayAdapter adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,list);
    listView.setAdapter(adapter);
}

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

    btn_checklist= findViewById(R.id.check_list_button);
    inputText=findViewById(R.id.inputText);
    listView=findViewById(R.id.listView);
    list = new ArrayList<>();
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...