Home>
I want to transition the screen from Main to Category
When you click the "Start" button on the Main screen, the application will end and the following error message will be displayed.
unfortunately, QuestionApplication has stopped.
Corresponding source code
activity_main.xml
<? xml version = "1.0" encoding = "utf-8"?><TextView
android: id = "@ + id/textPage"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "Main"
android: textSize = "30sp"
app: layout_constraintLeft_toLeftOf = "parent"
app: layout_constraintTop_toTopOf = "parent" /><Button
android: id = "@ + id/buttonStart"
android: layout_width = "250sp"
android: layout_height = "130sp"
android: text = "start"
android: textSize = "50sp"
app: layout_constraintTop_toTopOf = "parent"
app: layout_constraintBottom_toBottomOf = "parent"
app: layout_constraintLeft_toLeftOf = "parent"
app: layout_constraintRight_toRightOf = "parent" /></androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.questionapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;import android.widget.Button;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
Button btnS;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
btnS = (Button) findViewById (R.id.buttonStart);// Start button
btnS.setOnClickListener (new View.OnClickListener () {
public void onClick (View view) {
Intent intent = new Intent ();
intent.setClassName ("com.example.questionapp", "com.example.questionapp.CategoryActivity");
startActivity (intent);
}
});
}
}
activity_category.xml
<? xml version = "1.0" encoding = "utf-8"?><TextView
android: id = "@ + id/textPage"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "Category"
android: textSize = "30sp"
app: layout_constraintLeft_toLeftOf = "parent"
app: layout_constraintTop_toTopOf = "parent" /></androidx.constraintlayout.widget.ConstraintLayout>
CategoryActivity.java
package com.example.questionapplication;
import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.widget.TextView;
public class CategoryActivity extends AppCompatActivity {
TextView txtP;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_category);
txtP = (TextView) findViewById (R.id.textPage);
}
}
AndroidManifest.xml
<? xml version = "1.0" encoding = "utf-8"?><manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "com.example.questionapplication"> </activity> <intent-filter> <category android: name = "android.intent.category.LAUNCHER" /> </intent-filter> </activity></application></manifest>
What I tried
Re-enter and confirm AndroidManifest.xml
AVD Manager Data Erase
Android Studio 4.1
AVD: Nexus7 (2012) API23
SDK: Android 6.0 (Marshmallow) API level 23
-
Answer # 1
-
Answer # 2
Intent intent = new Intent (getApplication (), CategoryActivity.class);
Please try with.
Related articles
- [java] [android studio] screen transition method
- java - the screen transition does not go well
- java - i want to load a kml file into android studio and display the feature data on google map
- java - i want to fix an error in android studio
- [android studio] it crashes when the screen changes on the emulator
- java - delayed execution does not work well in android studio (postdelayed error)
- java - please tell me how to resolve the android studio error
- java - i want to open a site with a fixed url when i tap the icon of the android studio app
- java - in the screen transition between fragments, the view before the transition remains
- java - android i want to register multiple screen buttons at once in setonclicklistener
- java - screen transition does not work
- java - [android studio] switching to dark mode how to specify multiple textcolors in stylesxml
- java - about type conversion of view in android studio
- javafx screen transition error
- java - android studio xml preview does not show textview characters
- create an app with android studio "full screen activity" reference location
- java - error in android studio
- java - cannot pass data (screen transition) using servlet
- java - error when building android studio ml kit for firebase [plugin with id'comandroidapplication' not found]
Related questions
- java : It's not always possible to load data from Firebase
- java : Creating an object that depends on an object from another activity
- java : AAPT error: error: attribute android: hintTextColor not found
- java : How to update Recycler view with data from another thread?
- java : Animating the appearance /disappearance of items in the RecyclerView
- Tab content disappears after fragment reload (Android Studio Java)
- java : What is outerClass.get ()? .Tv_receive?
- java : SharedPreferences for persistence
- java : XML markup in Android application
- android : I want to always display a camera preview on the Surface View
The package name is
However, the package name and fully qualified class name set in Intent are
It has become.
question application
Whenquestionapp
It's different. This is the reason why it cannot be migrated normally.You should be able to migrate if you change to.