Reputation: 79
Please help me sorting out where I am wrong. Because when I start a new activity using a button click the app crashes. I am unable to figure out. I used another Acitvity from the same application and it launched successfully. But this nelwy created activity isn't starting in any ways.
My codes are:
[secondscreen.java]
package org......android.activities;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import org......android.R;
public class secondscreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondscreen);
TextView myAwesomeTextView = (TextView)findViewById(R.id.myAwesomeTextView);
myAwesomeTextView.setText("brown fox");
}
}
[activity_secondscreen.xml]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".activities.secondscreen">
<TextView
android:id="@+id/myAwesomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="secondscreen activity"
android:textSize="34sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
[starting activity code in a first activity]
buttonTraining = findViewById(R.id.buttonTraining);
buttonTraining.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(),"going to second activity...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),secondscreen.class);
startActivity(intent);
}
});
[partial stacktrace]
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Upvotes: 0
Views: 925
Reputation: 79
Worked. After Changed From
<activity
android:name=".activities.secondscreen"
android:exported="false"/>
to
<activity
android:name=".activities.secondscreen"
android:exported="false"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
Upvotes: 1