I'm a student doing a project on android studio, we're supposed to make a blood donation app. And for some reason, the build is successful but it says that the app has stopped. Here is the error on the menu and the XML file on main.
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.blooddonation, PID: 6978 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.blooddonation/com.example.blooddonation.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setText(java.lang.CharSequence)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) 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) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setText(java.lang.CharSequence)' on a null object reference at com.example.blooddonation.MainActivity.onCreate(MainActivity.java:32) at android.app.Activity.performCreate(Activity.java:8000) at android.app.Activity.performCreate(Activity.java:7984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) 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) W/System: A resource failed to call close.
XML on main:
<ImageView
android:layout_width="800px"
android:layout_height="1000px"
android:layout_marginTop="110dp"
android:src="@drawable/blooddonation"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Be the reason
someone's heart
beats stronger"
android:textSize="90px"
android:fontFamily="sans-serif"
android:textColor="@color/black"
android:gravity="center"
android:textStyle="bold"/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:fontFamily="sans-serif"
android:textStyle="bold"
android:textColor="@color/white"
android:background="@drawable/buttonlogin"
android:layout_marginTop="60px"
android:layout_gravity="center"/>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an account?"
android:layout_marginTop="40px"
android:layout_marginLeft="95dp"
android:textColor="@color/black"/>
<TextView
android:id="@+id/btnSignup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign up"
android:layout_marginTop="40px"
android:layout_marginLeft="15px"
android:textColor="#CA2525"
android:textStyle="bold"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>