启动导致应用程序崩溃的新活动



请帮我找出错误的地方。因为当我使用按钮点击启动一个新活动时,应用程序会崩溃。我想不通。我使用了同一应用程序中的另一个Acitvity,它成功启动了。但这种由nelwy创建的活动并没有以任何方式开始。

我的代码是:

[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.

工作。更改后来自

<activity
android:name=".activities.secondscreen"
android:exported="false"/>

<activity
android:name=".activities.secondscreen"
android:exported="false"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> 

最新更新