Whenever I try to open one of the activities in my app it causes a crash, it is only one of the four activities and this is whether I try to open it as the defaul or to open it via another activity.
Here is the XML for the activity in question
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".WelcomeScreen"> <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="@string/my_medicare" android:textSize="35dp" /> <TextView android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="90dp" android:text="@string/welcome" android:textSize="25dp" /> <Button android:id="@+id/b2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview2" android:layout_alignParentLeft="true" android:layout_marginStart="50dp" android:layout_marginLeft="50dp" android:layout_marginTop="250dp" android:text="@string/details" /> <Button android:id="@+id/b3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview2" android:layout_alignParentRight="true" android:layout_marginTop="250dp" android:layout_marginRight="50dp" android:text="@string/readings" /> </RelativeLayout>
Here is the Java for it
package com.example.mymedicare; import android.app.Activity; import android.os.Bundle; import android.content.Intent; import android.view.View; import android.widget.Button; public class WelcomeScreen extends Activity { Button b2, b3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome_screen); b2 = (Button) findViewById(R.id.button); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openDetails(); } }); setContentView(R.layout.activity_welcome_screen); b3 = (Button) findViewById(R.id.button); b3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openReadings(); } }); } public void openDetails() { Intent intent = new Intent(this, Details.class); startActivity(intent); } public void openReadings() { Intent intent = new Intent(this, Readings.class); startActivity(intent); } }
And here is the manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mymedicare"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyMediCare"> <activity android:name=".Readings"/> <activity android:name=".Details"/> <activity android:name=".WelcomeScreen"/> <activity android:name=".MainActivity"> <intent-filter> <action android:name = "android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
I'm still relatively new to android development and this is my first time posting here so please let me know if I missed out anything I'd need to include
https://stackoverflow.com/questions/67410932/activity-causing-android-studio-to-crash-on-open May 06, 2021 at 10:08AM
没有评论:
发表评论