小编Mar*_* D.的帖子

类型参数 t 具有不兼容的上限:视图和片段

我想获取我的活动片段,但我收到错误:

类型参数 t 具有不兼容的上限:视图和片段

findViewById(R.id.f_instruction)我的 MainActivity 中。我希望你可以帮助我。

我的活动:

public class MainActivity extends AppCompatActivity {
Fragment f_instruction;
public static void closeFragment() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    f_instruction = findViewById(R.id.f_instruction);
}
Run Code Online (Sandbox Code Playgroud)

}

活动 XML:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <fragment
        android:id="@+id/f_instruction"
        android:name="e.marco.gymdiary.first_fragment"
        android:layout_width="410dp"
        android:layout_height="732dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

java android fragment android-fragments

2
推荐指数
1
解决办法
740
查看次数

标签 统计

android ×1

android-fragments ×1

fragment ×1

java ×1