Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java E/AndroidRuntime:致命异常:android studio中的main_Java_Android - Fatal编程技术网

Java E/AndroidRuntime:致命异常:android studio中的main

Java E/AndroidRuntime:致命异常:android studio中的main,java,android,Java,Android,当我尝试运行时,它显示应用程序已停止,我在logcat中遇到以下错误: 12-18 21:47:44.545 26245-26245/com.example.bloodpressuremonitoring1 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.bloodpressuremonitoring1, PID: 26245 java.lang.RuntimeException: Unable to st

当我尝试运行时,它显示应用程序已停止,我在logcat中遇到以下错误:

12-18 21:47:44.545 26245-26245/com.example.bloodpressuremonitoring1 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.bloodpressuremonitoring1, PID: 26245
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bloodpressuremonitoring1/com.example.bloodpressuremonitoring1.MainActivity}: java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.ImageView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
        at android.app.ActivityThread.access$900(ActivityThread.java:177)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5910)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
     Caused by: java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.ImageView
        at com.example.bloodpressuremonitoring1.MainActivity.onCreate(MainActivity.java:28)
        at android.app.Activity.performCreate(Activity.java:6178)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
以下是我的MainActivity.java:

public class MainActivity extends AppCompatActivity {

    private static int SPLASH_SCREEN = 5000;

    //Variables
    Animation topAnim, bottomAnim;
    ImageView image;
    TextView logo, slogan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);

        //Animations
        topAnim = AnimationUtils.loadAnimation(this, R.anim.top_animation);
        bottomAnim = AnimationUtils.loadAnimation(this, R.anim.bottom_animation);

        //Hooks
        image = findViewById(R.id.imageView);
        logo = findViewById(R.id.textView);
        slogan = findViewById(R.id.textView2);

        image.setAnimation(topAnim);
        logo.setAnimation(bottomAnim);
        slogan.setAnimation(bottomAnim);

    }
}
以下是我的活动_main.xml:

<ImageView
    android:layout_width="266dp"
    android:layout_height="312dp"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="100dp"
    android:layout_marginEnd="10dp"
    android:layout_marginRight="10dp"
    android:src="@drawable/blood_pressure"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="50dp"
    android:fontFamily="@font/bilbo_swash_caps"
    android:gravity="center"
    android:text="Blood Pressure Monitoring"
    android:textSize="35sp"
    app:layout_constraintBottom_toTopOf="@+id/textView2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />


<TextView

    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="60dp"
    android:fontFamily="sans-serif-smallcaps"
    android:gravity="center"
    android:text="Monitor your blood pressure anytime"
    android:textSize="15sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />


请帮助我,非常感谢…

您的ImageView没有id

<ImageView
   android:id="@+id/imageView"
   ...
/>


可能是您不小心将
@+id/imageView
放在ConstraintLayout上了?

您不小心将imageView id添加到ConstraintLayout id中。只需更改即可。 错误: androidx.constraintlayout.widget.constraintlayout无法强制转换为android.widget.ImageView

您尚未为ImageView提供id。可能是给你错了。交叉检查并将imageView作为内部id提供