java Android Studio MainActivity即使在新项目上也不存在
我发布了一个关于我在安卓 studio中收到的空指针的问题,该指针与始终为空的上下文有关。此外,无论我如何分配它,这个错误都会不断出现
我一直无法找到这个问题的解决方案,所以决定开始一个全新的项目——不写一行代码,我也会遇到同样的错误
控制台错误
$ adb shell am start -n "za.co.freelanceweb.scheduler/za.co.freelanceweb.scheduler.MainActivity" -a 安卓.intent.action.MAIN -c 安卓.intent.category.LAUNCHER
Error while executing: am start -n "za.co.freelanceweb.scheduler/za.co.freelanceweb.scheduler.MainActivity" -a 安卓.intent.action.MAIN -c 安卓.intent.category.LAUNCHER
Starting: Intent { act=安卓.intent.action.MAIN cat=[安卓.intent.category.LAUNCHER] cmp=za.co.freelanceweb.scheduler/.MainActivity }
Error type 3
Error: Activity class {za.co.freelanceweb.scheduler/za.co.freelanceweb.scheduler.MainActivity} does not exist.
Error while Launching activity
AndroidManifest。xml(未触及)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="za.co.freelanceweb.scheduler">
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:roundIcon="@mipmap/ic_launcher_round"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity 安卓:name=".MainActivity">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
gradle项目文件(未触及)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.安卓.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle应用程序文件(未触及)
apply plugin: 'com.安卓.application'
安卓 {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "za.co.freelanceweb.scheduler"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "安卓x.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-安卓-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation '安卓x.appcompat:appcompat:1.1.0'
implementation '安卓x.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
安卓TestImplementation '安卓x.test:runner:1.2.0'
安卓TestImplementation '安卓x.test.espresso:espresso-core:3.2.0'
}
主要活动。java(未触及)
package za.co.freelanceweb.scheduler;
import 安卓x.appcompat.app.AppCompatActivity;
import 安卓.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
# 1 楼答案
Delete this Three folder and restart android Studio . Doing this will not delete your old project. But don't delete the Android Studio project folder