gpt4 book ai didi

java - Activity 未找到异常 : Unable to find explicit activity class?

转载 作者:行者123 更新时间:2023-12-01 18:00:29 28 4
gpt4 key购买 nike


是的,我知道这个问题已经被问过很多次了,但没有一个答案对我真正有用?我想也许有人只需要解释我的代码。

我的应用程序在 SplashScreen.java 上启动 10 秒,然后应该加载 MainActivity.java 。但是,当我运行我的应用程序时,它启动了 SplashScreen,但 10 秒后,MainActivity 未加载,应用程序说它已停止。

我检查了运行日志,它说“android.content.ActivityNotFoundException:找不到显式 Activity 类 {com.msp.supercarsounds/com.msp.supercarsounds.MainActivity};您是否在 AndroidManifest.xml 中声明了此 Activity ?”

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">

<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>

<uses-permission
android:name="android.permission.INTERNET"/>

<application
android:largeHeap="true"
android:allowBackup="true"
android:icon="@mipmap/carsounds_logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.msp.supercarsounds.SplashScreen"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<activity
android:name="com.msp.supercarsounds.MainActivity" />

<activity
android:name=".AudiPrimary"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.RegisterApplication"
android:label="Register Appliction"
android:theme="@style/AppTheme" />

<activity
android:name="com.msp.supercarsounds.Porsche"
android:label="Porsche"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.MercedesBenz"
android:label="Mercedes-Benz"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.Lamborghini"
android:label="Lamborghini"
android:theme="@style/AppTheme" />

<activity
android:name="com.msp.supercarsounds.Ferrari"
android:label="Ferrari"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.BMW"
android:label="BMW"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.Jaguar"
android:label="Jaguar"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.AstonMartin"
android:label="Aston Martin"
android:theme="@style/AppTheme" />

<activity
android:name="com.msp.supercarsounds.ChooseManufacturer"
android:label="Choose Manufacturer"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.Audi"
android:label="Audi"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<activity
android:name="com.msp.supercarsounds.About"
android:label="About"
android:theme="@style/AppTheme" />

<activity
android:name="com.msp.supercarsounds.Contact"
android:label="Contact"
android:theme="@style/AppTheme" />

<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action
android:name="com.google.firebase.MESSAGING.EVENT"/>
</intent-filter>
</service>

<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action
android:name="com.google.firebase.INSTANCE.ID.EVENT"/>
</intent-filter>
</service>

</manifest>


SplashScreen.java:

package com.msp.supercarsounds;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class SplashScreen extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen_layout);

Thread myThread = new Thread() {

@Override
public void run() {
try {
sleep(10000);
Intent startMainActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(startMainActivity);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
};
myThread.start();
}


}

MainActivity.java:

package com.msp.supercarsounds;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;


public class MainActivity extends AppCompatActivity {

public static final String PREFS_NAME = "MyPrefsFile1";
public CheckBox dontShowAgain;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}


public void clickedAbout(View view) {

final int result = 1;

Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);

}

public void clickedContact(View view) {

final int result = 1;

Intent ContactButtonClicked = new Intent (this, Contact.class);
ContactButtonClicked.putExtra("Contact", "MainActivity");
startActivityForResult(ContactButtonClicked, result);

}
@Override
protected void onResume() {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
LayoutInflater adbInflater = LayoutInflater.from(this);
View eulaLayout = adbInflater.inflate(R.layout.checkbox, null);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String skipMessage = settings.getString("skipMessage", "NOT checked");

dontShowAgain = (CheckBox) eulaLayout.findViewById(R.id.skip);
adb.setView(eulaLayout);
adb.setTitle("PLEASE REGISTER THIS APPLICATION!");
adb.setMessage(Html.fromHtml("Please register this application in order to receive newer versions and support!"));

adb.setPositiveButton("I understand", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String checkBoxResult = "NOT checked";

if (dontShowAgain.isChecked()) {
checkBoxResult = "checked";
}

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();

editor.putString("skipMessage", checkBoxResult);
editor.commit();

// Do what you want to do on "OK" action

return;
}
});

adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String checkBoxResult = "NOT checked";

if (dontShowAgain.isChecked()) {
checkBoxResult = "checked";
}

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();

editor.putString("skipMessage", checkBoxResult);
editor.commit();


return;
}
});

if (!skipMessage.equals("checked")) {
adb.show();
}

super.onResume();
}

public void clickedSettings(MenuItem item) {

final int result = 1;

Intent SettingsButtonClicked = new Intent (this, About.class);
SettingsButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(SettingsButtonClicked, result);

}

public void clickedSupercarSounds(View view) {

final int result = 1;

Intent SupercarSoundsButtonClicked = new Intent (this, ChooseManufacturer.class);
SupercarSoundsButtonClicked.putExtra("Choose Manufacturer", "MainActivity");
startActivityForResult(SupercarSoundsButtonClicked, result);

}

public void clickedRegisterApplication(View view) {

final int result = 1;

Intent RegisterApplicationButtonClicked = new Intent (this, RegisterApplication.class);
RegisterApplicationButtonClicked.putExtra("Register Application", "MainActivity");
startActivityForResult(RegisterApplicationButtonClicked, result);

}

}

谢谢!

最佳答案

您需要放置您的<activity> <application> 中的标签AndroidManifest.xml 中的标记。

关于java - Activity 未找到异常 : Unable to find explicit activity class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41401991/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com